File Coverage

File:lib/WWW/Google/Contacts/InternalTypes.pm
Coverage:100.0%

linestmtbrancondsubpodtimecode
1package WWW::Google::Contacts::InternalTypes;
2
3
12
135
use MooseX::Types -declare =>
4    [ qw(
5            XmlBool
6            Rel
7            When
8            Method
9
12
12
99
38
    ) ];
10
11
12
12
12
126
38
102
use MooseX::Types::Moose qw(Str Bool HashRef CodeRef Any);
12
13subtype Method,
14    as CodeRef;
15
16coerce Method,
17    from Any,
18    via { sub { return $_ } };
19
20class_type Rel,
21    { class => 'WWW::Google::Contacts::Type::Rel' };
22
23coerce Rel,
24    from Str,
25    via {
26        require WWW::Google::Contacts::Type::Rel;
27        WWW::Google::Contacts::Type::Rel->new(
28            ($_ =~ m{^http})
29                ? ( uri => $_ )
30                    : ( name => $_ ),
31        );
32    };
33
34subtype XmlBool,
35    as Bool;
36
37coerce XmlBool,
38    from Str,
39    via {
40        return 1 if ( $_ =~ m{^true$}i );
41        return 0;
42    };
43
44class_type When,
45    { class => 'WWW::Google::Contacts::Type::When' };
46
47coerce When,
48    from Str,
49    via {
50        require WWW::Google::Contacts::Type::When;
51        WWW::Google::Contacts::Type::When->new( start_time => $_ );
52    },
53    from HashRef,
54    via {
55        return undef unless defined $_->{ startTime };
56        require WWW::Google::Contacts::Type::When;
57        WWW::Google::Contacts::Type::When->new(
58            start_time => $_->{ startTime },
59            defined $_->{ endTime } ? ( end_time => $_->{ endTime } ) : (),
60        );
61    };