File Coverage

File:lib/WWW/Google/Contacts/Group.pm
Coverage:50.0%

linestmtbrancondsubpodtimecode
1package WWW::Google::Contacts::Group;
2
3
11
11
11
86
36
90
use Moose;
4
11
11
11
130
35
102
use MooseX::Types::Moose qw( Str );
5
11
133
use WWW::Google::Contacts::Types qw(
6                                       Category
7
11
11
283
35
                               );
8
9
11
11
11
115
37
169
use WWW::Google::Contacts::Meta::Attribute::Trait::XmlField;
10
11
0
0
sub create_url { 'http://www.google.com/m8/feeds/groups/default/full' }
12
13extends 'WWW::Google::Contacts::Base';
14
15with 'WWW::Google::Contacts::Roles::CRUD';
16
17has id => (
18    isa => Str,
19    is => 'ro',
20    writer => '_set_id',
21    predicate => 'has_id',
22    traits => [ 'XmlField' ],
23    xml_key => 'id',
24);
25
26has etag => (
27    isa => Str,
28    is => 'ro',
29    writer => '_set_etag',
30    predicate => 'has_etag',
31    traits => [ 'XmlField' ],
32    xml_key => 'gd:etag',
33    include_in_xml => 0, # This is set in HTTP headers
34);
35
36has category => (
37    isa => Category,
38    is => 'rw',
39    predicate => 'has_category',
40    traits => [ 'XmlField' ],
41    xml_key => 'category',
42    default => sub { undef },
43    coerce => 1,
44);
45
46has title => (
47    isa => Str,
48    is => 'rw',
49    predicate => 'has_title',
50    traits => [ 'XmlField' ],
51    xml_key => 'title',
52    is_element => 1,
53);
54
55has member => (
56    is => 'ro',
57    lazy_build => 1,
58);
59
60has link => (
61    is => 'rw',
62    trigger => \&_set_link,
63    traits => [ 'XmlField' ],
64    xml_key => 'link',
65    include_in_xml => 0,
66);
67
68# What to do with different link types
69my $link_map = {
70    'self'
71        => sub { my ($self,$link) = @_; $self->_set_id( $link->{ href } ) },
72};
73
74sub _set_link {
75
0
    my ($self, $links) = @_;
76
0
    $links = ref($links) eq 'ARRAY' ? $links : [ $links ];
77
0
0
    foreach my $link ( @{ $links } ) {
78
0
        next unless ( defined $link_map->{ $link->{ rel } } );
79
0
        my $code = $link_map->{ $link->{ rel } };
80
0
        $link->{href} =~ s{/full/}{/base/};
81
0
        $self->$code( $link );
82    }
83}
84
85sub _build_member {
86
0
    my $self = shift;
87
0
    my $list = WWW::Google::Contacts::ContactList->new( server => $self->server );
88
0
    return $list->search({ group_membership => $self->id });
89}
90
91
11
11
11
112
37
91
no Moose;
92__PACKAGE__->meta->make_immutable;
931;