DataAPI.pm

filter: Statementstmt 94.5% 140 / 148 Branchbran 86.1% 62 / 72 Conditioncond 84.6% 22 / 26 MC/DCmcdc 62.5% 10 / 16 Subroutinesub 89.6% 26 / 29 Podpod 100% 2 / 2 totaltotal 89.4% 262 / 293 CC 79 SCAR 14.3
CC
79
Cov
91%
entry_has
11.0
feedurl
7.1
__ANON__
4.1
CRAP 4.2
« DataAPI/Auth/ClientLogin/Multiple.pm ↑ Summary DataAPI/Role/Entry.pm »
1 package Net::Google::DataAPI;
2 12 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Any::Moose '::Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Lingua::EN::Inflect::Number qw(to_PL);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use XML::Atom;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 our $VERSION = '0.2802_2';
9  
10 12 any_moose('::Exporter')->setup_import_methods(
11 as_is => ['feedurl', 'entry_has'],
12 );
13  
14 sub feedurl {
15 38 ▶ my ($name, %args) = @_;
Subroutine feedurl: called CC=7 SCAR=19.6
Pod documented
16  
17 38 my $class = caller;
18  
19 my $entry_class = delete $args{entry_class}
20 38 ▶ or confess 'entry_class not specified';
Branch: 1 branch
BranchTrueFalseTotal
my $entry_class = delete $args{"entry_class"} or confess("entry_class not specified") 1 37 38
21  
22 37 my $can_add = delete $args{can_add};
23 37 ▶ $can_add = 1 unless defined $can_add;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $can_add 31 6 37
24  
25 my $arg_builder = delete $args{arg_builder}
26 || sub {
27 6 ▶ my ($self, $args) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
28 6 ▶ return $args || {};
Condition100%2/2
$args || {}
l!l
33
MC/DC100%1/1
$args || {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
29 37 ▶ };
Condition66%2/3
delete $args{'arg_builder'} || sub {
l!l&&r!l&&!r
4330
MC/DC0%0/2
delete $args{'arg_builder'} || sub { my($self, $args) = @_; return $args || {}; }
delete $args{'arg_builder'} sub { my($self, $args) = @_; return $args || {}; }
Truth table66%2/3
A || B
A= delete $args{'arg_builder'}B= sub { my($self, $args) = @_; return $args || {}; }
ABresult
1X1
011
000
30  
31 my $query_builder = delete $args{query_builder}
32 || sub {
33 18 ▶ my ($self, $args) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
34 18 ▶ return $args || {};
Condition100%2/2
$args || {}
l!l
315
MC/DC100%1/1
$args || {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
35 37 ▶ };
Condition66%2/3
delete $args{'query_builder'} || sub {
l!l&&r!l&&!r
4330
MC/DC0%0/2
delete $args{'query_builder'} || sub { my($self, $args) = @_; return $args || {}; }
delete $args{'query_builder'} sub { my($self, $args) = @_; return $args || {}; }
Truth table66%2/3
A || B
A= delete $args{'query_builder'}B= sub { my($self, $args) = @_; return $args || {}; }
ABresult
1X1
011
000
36  
37 37 my $from_atom = delete $args{from_atom};
38 37 my $rel = delete $args{rel};
39 37 my $as_content_src = delete $args{as_content_src};
40 37 ▶ my $default = delete $args{default} || '';
Condition100%2/2
delete $args{'default'} || ''
l!l
1918
MC/DC100%1/1
delete $args{'default'} || ''
delete $args{'default'}
Truth table100%2/2
A
A= delete $args{'default'}
Aresult
11
00
41  
42 37 my $attr_name = "${name}_feedurl";
43  
44 37 my $class_meta = any_moose('::Meta::Class')->initialize($class);
45 37 $class_meta->add_attribute(
46 $attr_name => (
47 isa => 'Str',
48 is => 'ro',
49 lazy_build => 1,
50 %args,
51 )
52 );
53 $class_meta->add_method(
54 0 ▶ "${name}_entryclass" => sub { $entry_class }
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine fixed_entryclass: called CC=1 SCAR=1.2
55 37 );
56  
57 $class_meta->add_method(
58 "_build_$attr_name" => sub {
59 9 ▶ my $self = shift;
Subroutine __ANON__: called CC=4 SCAR=14.0
Subroutine _build_src_child_feedurl: called CC=4 SCAR=14.0
60 return $rel ?
61 [
62 1 map { $_->href }
63 9 ▶ grep { $_->rel eq $rel }
Branch: 6 branches
BranchTrueFalseTotal
$rel ? : 1 8 9
$as_content_src ? : 0 8 8
$from_atom ? : 0 8 8
$rel ? : 2 2 4
$as_content_src ? : 2 2 4
$from_atom ? : 0 7 7
64 $self->atom->link
65 ]->[0] :
66 $as_content_src ?
67 $self->atom->content->elem->getAttribute('src') :
68 $from_atom ?
69 $from_atom->($self, $self->atom) : $default;
70 }
71 37 );
72 37 my $pl_name = to_PL($name);
73  
74 37 ▶ if ($can_add) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_add) 31 6 37
75 $class_meta->add_method(
76 "add_$name" => sub {
77 4 ▶ my ($self, $args) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
Subroutine add_null_child: called CC=4 SCAR=13.9
78 4 ▶ $self->$attr_name or confess "$attr_name is not set";
Branch: 2 branches
BranchTrueFalseTotal
$self->$attr_name or confess("$attr_name is not set") 1 3 4
$self->$attr_name or confess("$attr_name is not set") 0 7 7
79 3 Any::Moose::load_class($entry_class);
80 3 $args = $arg_builder->($self, $args);
81 3 ▶ my %parent =
Branch: 2 branches
BranchTrueFalseTotal
$self->can('sync') ? : 1 2 3
$self->can('sync') ? : 0 2 2
82 $self->can('sync') ?
83 ( container => $self ) : ( service => $self );
84 3 my $entry = $entry_class->new(
85 {
86 %parent,
87 %$args
88 }
89 )->to_atom;
90 3 my $atom = $self->service->post($self->$attr_name, $entry);
91 3 ▶ $self->sync if $self->can('sync');
Branch: 2 branches
BranchTrueFalseTotal
if $self->can("sync") 1 2 3
if $self->can("sync") 0 13 13
92 3 my $e = $entry_class->new(
93 %parent,
94 atom => $atom,
95 );
96 3 return $e;
97 }
98 31 );
99 }
100 $class_meta->add_method(
101 $pl_name => sub {
102 13 ▶ my ($self, $cond) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
Subroutine myentries: called CC=4 SCAR=13.9
Subroutine fixeds: not called CC=4 SCAR=13.9
103 13 my $feed = do {
104 13 ▶ if (ref($cond) eq 'XML::Atom::Feed') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cond eq 'XML::Atom::Feed') { } 1 12 13
if (ref $cond eq 'XML::Atom::Feed') { } 5 22 27
105 1 $cond;
106 } else {
107 12 ▶ $self->$attr_name or confess "$attr_name is not set";
Branch: 2 branches
BranchTrueFalseTotal
$self->$attr_name or confess("$attr_name is not set") 1 11 12
$self->$attr_name or confess("$attr_name is not set") 7 15 22
108 11 Any::Moose::load_class($entry_class);
109 11 $self->can("${name}_feed")->($self, $cond);
110 }
111 };
112 return map {
113 12 ▶ $entry_class->new(
Branch: 2 branches
BranchTrueFalseTotal
$self->can('sync') ? : 1 13 14
$self->can('sync') ? : 5 10 15
114 $self->can('sync') ?
115 ( container => $self ) : ( service => $self ),
116 atom => $_,
117 )
118 } $feed->entries;
119 }
120 37 );
121 $class_meta->add_method(
122 "${name}_feed" => sub {
123 0 ▶ my ($self, $cond) = @_;
Subroutine __ANON__: not called CC=2 SCAR=10.3
Subroutine myentry_feed: called CC=2 SCAR=10.3
124 0 ▶ $self->$attr_name or confess "$attr_name is not set";
Branch: 2 branches
BranchTrueFalseTotal
$self->$attr_name or confess("$attr_name is not set") 0 0 0
$self->$attr_name or confess("$attr_name is not set") 0 10 10
125 0 $cond = $query_builder->($self, $cond);
126 0 return $self->service->get_feed($self->$attr_name, $cond);
127 }
128 37 );
129 $class_meta->add_method(
130 $name => sub {
131 11 ▶ my ($self, $cond) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
132 11 return [ $self->$pl_name($cond) ]->[0];
133 }
134 37 );
135  
136 }
137  
138 sub entry_has {
139 10 ▶ my ($name, %args) = @_;
Subroutine entry_has: called CC=11 SCAR=24.0
Pod documented
140  
141 10 my $class = caller;
142 10 my $class_meta = any_moose('::Meta::Class')->initialize($class);
143 10 ▶ $class_meta->does_role('Net::Google::DataAPI::Role::Entry')
Branch: 1 branch
BranchTrueFalseTotal
$class_meta->does_role("Net::Google::DataAPI::Role::Entry") or confess("Net::Google::DataAPI::Role::Entry required to use entry_has") 1 9 10
144 or confess 'Net::Google::DataAPI::Role::Entry required to use entry_has';
145  
146 9 my $tagname = delete $args{tagname};
147 9 my $ns = delete $args{ns};
148  
149 9 my $from_atom = delete $args{from_atom};
150 9 my $to_atom = delete $args{to_atom};
151 9 ▶ my $default = delete $args{default} || '';
Condition100%2/2
delete $args{'default'} || ''
l!l
18
MC/DC100%1/1
delete $args{'default'} || ''
delete $args{'default'}
Truth table100%2/2
A
A= delete $args{'default'}
Aresult
11
00
152 9 ▶ $default = $default->() if ref $default eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $default eq "CODE" 1 8 9
153  
154 $class_meta->add_attribute(
155 $name => (
156 isa => 'Str',
157 is => 'ro',
158 $to_atom || $tagname ? (
159 7 ▶ trigger => sub {$_[0]->update }
Subroutine __ANON__: called CC=1 SCAR=0.0
160 9 ▶ ) : (),
Branch: 2 branches
BranchTrueFalseTotal
$to_atom || $tagname ? : 8 1 9
$tagname || $from_atom ? : 8 1 9
Condition100%6/6
$to_atom or $tagname
l!l&&r!l&&!r
171
$tagname or $from_atom
l!l&&r!l&&!r
711
MC/DC100%2/2
$to_atom or $tagname
$to_atom $tagname
MC/DC100%2/2
$tagname or $from_atom
$tagname $from_atom
Truth table100%3/3
A or B
A= $to_atomB= $tagname
ABresult
1X1
011
000
Truth table100%3/3
A or B
A= $tagnameB= $from_atom
ABresult
1X1
011
000
161 $tagname || $from_atom ? (
162 lazy_build => 1,
163 ) : (),
164 %args,
165 )
166 );
167 9 ▶ if ($tagname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagname) 7 2 9
168 $class_meta->add_around_method_modifier(
169 to_atom => sub {
170 8 ▶ my ($next, $self) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
171 8 my $entry = $next->($self);
172 8 ▶ my $ns_obj = $ns ? $self->ns($ns) : $entry->ns;
Branch: 1 branch
BranchTrueFalseTotal
$ns ? : 3 5 8
173 8 ▶ $entry->set($ns_obj, $tagname, $self->$name) if $self->$name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$name 4 4 8
174 8 return $entry;
175 }
176 7 );
177 $class_meta->add_method(
178 "_build_$name" => sub {
179 11 ▶ my $self = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
180 11 ▶ $self->atom or return $default;
Branch: 1 branch
BranchTrueFalseTotal
$self->atom or return $default 3 8 11
181 8 ▶ my $ns_obj = $ns ? $self->ns($ns) : $self->atom->ns;
Branch: 1 branch
BranchTrueFalseTotal
$ns ? : 6 2 8
182 8 ▶ return $self->atom->get($ns_obj, $tagname) || $default;
Condition66%2/3
$self->atom->get($ns_obj, $tagname) || $default
l!l&&r!l&&!r
701
MC/DC50%1/2
$self->atom->get($ns_obj, $tagname) || $default
$self->atom->get($ns_obj, $tagname) $default
Truth table66%2/3
A || B
A= $self->atom->get($ns_obj, $tagname)B= $default
ABresult
1X1
011
000
183 }
184 7 );
185 }
186 9 ▶ if ($to_atom) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_atom) 1 8 9
187 $class_meta->add_around_method_modifier(
188 to_atom => sub {
189 2 ▶ my ($next, $self) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
190 2 my $entry = $next->($self);
191 2 ▶ $to_atom->($self, $entry) if $self->$name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$name 1 1 2
192 2 return $entry;
193 }
194 1 );
195 }
196 9 ▶ if ($from_atom) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from_atom) 1 8 9
197 $class_meta->add_method(
198 "_build_$name" => sub {
199 4 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.4
200 4 ▶ $self->atom or return $default;
Branch: 1 branch
BranchTrueFalseTotal
$self->atom or return $default 0 4 4
201 4 ▶ return $from_atom->($self, $self->atom) || $default;
Condition66%2/3
&$from_atom($self, $self->atom) || $default
l!l&&r!l&&!r
202
MC/DC50%1/2
&$from_atom($self, $self->atom) || $default
&$from_atom($self, $self->atom) $default
Truth table66%2/3
A || B
A= &$from_atom($self, $self->atom)B= $default
ABresult
1X1
011
000
202 }
203 1 );
204 }
205 }
206  
207 12 __PACKAGE__->meta->make_immutable;
208 12 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
209 12 ▶no Any::Moose '::Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
210  
211 12 1;
212 __END__
213  
214 =head1 NAME
215  
216 Net::Google::DataAPI - Base implementations for modules to negotiate with Google Data APIs
217  
218 =head1 SYNOPSIS
219  
220 package MyService;
221 use Any::Moose;
222 use Net::Google::DataAPI;
223  
224 with 'Net::Google::DataAPI::Role::Service';
225  
226 # registering xmlns
227 has '+namespaces' => (
228 default => {
229 foobar => 'http://example.com/schema#foobar',
230 },
231 );
232  
233 # registering feed url
234 feedurl myentry => (
235 entry_class => 'MyEntry',
236 # class name for the entry
237 default => 'http://example.com/myfeed',
238 );
239  
240 sub _build_auth {
241 my ($self) = @_;
242 # .. authsub login things, this is optional.
243 # see Net::Google::Spreadsheets for typical implementation
244 my $authsub = Net::Google::DataAPI::Auth::AuthSub->new(
245 service => 'wise',
246 account_type => 'HOSTED_OR_GOOGLE',
247 );
248 $authsub->login('foo.bar@gmail.com', 'p4ssw0rd');
249 return $authsub;
250 }
251  
252 1;
253  
254 package MyEntry;
255 use Any::Moose;
256 use Net::Google::DataAPI;
257 with 'Net::Google::DataAPI::Role::Entry';
258  
259 entry_has some_value => (
260 is => 'rw',
261 isa => 'Str',
262 # tagname
263 tagname => 'some_value',
264 # namespace
265 namespace => 'gd',
266 );
267  
268 1;
269  
270 =head1 DESCRIPTION
271  
272 Net::Google::DataAPI is base implementations for modules to negotiate with Google Data APIs.
273  
274 =head1 METHODS
275  
276 =head2 feedurl
277  
278 define a feed url.
279  
280 =head2 entry_has
281  
282 define a entry attribute.
283  
284 =head1 DEBUGGING
285  
286 You can set environment variable GOOGLE_DATAAPI_DEBUG=1 to see the raw requests and responses Net::Google::DataAPI sends and receives.
287  
288 =head1 AUTHOR
289  
290 Nobuo Danjou E<lt>danjou@soffritto.orgE<gt>
291  
292 =head1 TODO
293  
294 more pods.
295  
296 =head1 SEE ALSO
297  
298 L<Net::Google::AuthSub>
299  
300 L<Net::Google::DataAPI::Auth::AuthSub>
301  
302 L<Net::Google::DataAPI::Auth::ClientLogin::Multiple>
303  
304 L<Net::Google::DataAPI::Auth::OAuth>
305  
306 L<Net::Google::DataAPI::Role::Service>
307  
308 L<Net::Google::DataAPI::Role::Entry>
309  
310 =head1 LICENSE
311  
312 This library is free software; you can redistribute it and/or modify
313 it under the same terms as Perl itself.
314  
315 =cut
« DataAPI/Auth/ClientLogin/Multiple.pm ↑ Summary DataAPI/Role/Entry.pm »