DocumentsList/Role/EnsureListed.pm

filter: Statementstmt 9.2% 6 / 65 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 16.6% 1 / 6 Podpod 0.0% 0 / 4 totaltotal 5.1% 7 / 136 CC 30 SCAR 42.6
CC
30
Cov
5%
ensure_listed
110.0
ensure_trashed
90.0
ensure_deleted
56.0
CRAP 71.1
« DocumentsList/Role/HasItems.pm ↑ Summary DocumentsList/Role/Exportable.pm »
1 package Net::Google::DocumentsList::Role::EnsureListed;
2 14 ▶use Any::Moose '::Role';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 14 our $SLEEP = 1;
5 14 our $RETRY = 10;
6  
7 0 ▶sub ensure_listed {
Subroutine ensure_listed: not called CC=10 SCAR=47.0
Pod undocumented
8 0 my ($self, $item, $args) = @_;
9 0 for (1 .. $RETRY) {
10 0 my @items = $self->item(
11 {
12 resource_id => $item->resource_id,
13 title => $item->title,
14 'title-exact' => 'true',
15 category => $item->kind,
16 }
17 );
18 0 ▶ grep {$_ && $_->id eq $item->id} @items and last;
Branch: 1 branch
BranchTrueFalseTotal
grep {$_ and $_->id eq $item->id;} @items and last 0 0 0
Condition0%0/3
$_ && $_->id eq $item->id
!ll&&!rl&&r
000
MC/DC0%0/2
$_ && $_->id eq $item->id
$_ $_->id eq $item->id
Truth table0%0/3
A && B
A= $_B= $_->id eq $item->id
ABresult
0X0
100
111
19 0 sleep $SLEEP;
20 }
21 0 my $found_item;
22 0 for (1 .. $RETRY) {
23 0 $found_item = $self->_find_entry($item);
24 0 ▶ if ($found_item->title ne $item->title) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_item->title ne $item->title) 0 0 0
25 0 undef $found_item;
26 0 sleep $SLEEP;
27 0 next;
28 }
29 0 ▶ if ($args->{etag_should_change}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"etag_should_change"}) 0 0 0
30 0 ▶ $found_item->etag eq $item->etag and next;
Branch: 1 branch
BranchTrueFalseTotal
$found_item->etag eq $item->etag and next 0 0 0
31 # retry, but keep $found_item (it would the the true item)
32 }
33 0 last;
34 }
35 0 ▶ $found_item or confess "updated entry couldn't be retrieved";
Branch: 1 branch
BranchTrueFalseTotal
$found_item or confess("updated entry couldn't be retrieved") 0 0 0
36 0 ▶ $item->container->sync if $item->container;
Branch: 1 branch
BranchTrueFalseTotal
if $item->container 0 0 0
37 0 return $found_item;
38 }
39  
40 0 ▶sub ensure_not_listed {
Subroutine ensure_not_listed: not called CC=5 SCAR=34.0
Pod undocumented
41 0 my ($self, $folder) = @_;
42  
43 0 my $found;
44 0 for (1 .. $RETRY) {
45 0 undef $found;
46 0 my @list = $folder->item(
47 {
48 resource_id => $self->resource_id,
49 title => $self->title,
50 'title-exact' => 'true',
51 category => $self->kind,
52 }
53 );
54 0 ▶ ($found) = grep {$_ && $_->id eq $self->id} @list or last;
Branch: 1 branch
BranchTrueFalseTotal
($found) = grep({$_ and $_->id eq $self->id;} @list) or last 0 0 0
Condition0%0/3
$_ && $_->id eq $self->id
!ll&&!rl&&r
000
MC/DC0%0/2
$_ && $_->id eq $self->id
$_ $_->id eq $self->id
Truth table0%0/3
A && B
A= $_B= $_->id eq $self->id
ABresult
0X0
100
111
55 0 sleep $SLEEP;
56 }
57 0 ▶ $found and confess "item couldn't be moved";
Branch: 1 branch
BranchTrueFalseTotal
$found and confess("item couldn't be moved") 0 0 0
58 }
59  
60 0 ▶sub ensure_trashed {
Subroutine ensure_trashed: not called CC=9 SCAR=45.0
Pod undocumented
61 0 my ($self, $item) = @_;
62 0 my $found_item;
63 0 for (1 .. $RETRY) {
64 0 my @items = $self->item(
65 {
66 resource_id => $item->resource_id,
67 title => $item->title,
68 'title-exact' => 'true',
69 category => [$item->kind, 'trashed'],
70 }
71 );
72 0 ▶ my ($found) = grep {$_ && $_->id eq $item->id && $_->deleted} @items and last;
Branch: 1 branch
BranchTrueFalseTotal
my($found) = grep({$_ and $_->id eq $item->id and $_->deleted;} @items) and last 0 0 0
Condition0%0/6
$_ && $_->id eq $item->id && $_->deleted
!ll&&!rl&&r
000
$_ and $_->id eq $item->id
!ll&&!rl&&r
000
MC/DC0%0/3
$_ && $_->id eq $item->id && $_->deleted
$_ $_->id eq $item->id $_->deleted
Truth table0%0/4
A and B && C
A= $_B= $_->id eq $item->idC= $_->deleted
ABCresult
0XX0
10X0
1100
1111
73 0 sleep $SLEEP;
74 }
75 0 for (1 .. $RETRY) {
76 0 $found_item = $self->_find_entry($item);
77 0 ▶ $found_item->title eq $item->title && $found_item->deleted and last;
Branch: 1 branch
BranchTrueFalseTotal
$found_item->title eq $item->title and $found_item->deleted and last 0 0 0
Condition0%0/3
$found_item->title eq $item->title and $found_item->deleted
!ll&&!rl&&r
000
MC/DC0%0/2
$found_item->title eq $item->title and $found_item->deleted
$found_item->title eq $item->title $found_item->deleted
Truth table0%0/3
A and B
A= $found_item->title eq $item->titleB= $found_item->deleted
ABresult
0X0
100
111
78 0 undef $found_item;
79 0 sleep $SLEEP;
80 }
81 0 ▶ $found_item or confess "couldn't trash the item";
Branch: 1 branch
BranchTrueFalseTotal
$found_item or confess("couldn't trash the item") 0 0 0
82 }
83  
84 0 ▶sub ensure_deleted {
Subroutine ensure_deleted: not called CC=7 SCAR=40.3
Pod undocumented
85 0 my ($self, $item) = @_;
86 0 my $found_item;
87 0 for (1 .. $RETRY) {
88 0 my @items = $self->service->item(
89 {
90 resource_id => $item->resource_id,
91 title => $item->title,
92 'title-exact' => 'true',
93 category => $item->kind,
94 }
95 );
96 0 push @items, $self->service->item(
97 {
98 resource_id => $item->resource_id,
99 title => $item->title,
100 'title-exact' => 'true',
101 category => [$item->kind, 'trashed'],
102 }
103 );
104 0 ▶ grep {$_ && $_->id eq $item->id} @items or last;
Branch: 1 branch
BranchTrueFalseTotal
grep {$_ and $_->id eq $item->id;} @items or last 0 0 0
Condition0%0/3
$_ && $_->id eq $item->id
!ll&&!rl&&r
000
MC/DC0%0/2
$_ && $_->id eq $item->id
$_ $_->id eq $item->id
Truth table0%0/3
A && B
A= $_B= $_->id eq $item->id
ABresult
0X0
100
111
105 0 sleep $SLEEP;
106 }
107 0 my $found;
108 0 for (1 .. $RETRY) {
109 0 undef $found;
110 0 ▶ $found = eval {$self->_find_entry($item)} or last;
Branch: 1 branch
BranchTrueFalseTotal
$found = eval { do { $self->_find_entry($item) } } or last 0 0 0
111 0 sleep $SLEEP;
112 }
113 0 ▶ $found and confess "couldn't delete the item";
Branch: 1 branch
BranchTrueFalseTotal
$found and confess("couldn't delete the item") 0 0 0
114 }
115  
116 0 ▶sub _find_entry {
Subroutine _find_entry: not called CC=3 SCAR=24.8
117 0 my ($self, $item) = @_;
118 0 ▶ my $found = $self->service->get_entry($item->selfurl) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $found = $self->service->get_entry($item->selfurl) or return 0 0 0
119 0 ▶ return (ref $item)->new(
Branch: 1 branch
BranchTrueFalseTotal
$item->container ? : 0 0 0
120 $item->container ? (container => $item->container)
121 : ( service => $self->service),
122 atom => $found,
123 );
124 }
125  
126 14 1;
« DocumentsList/Role/HasItems.pm ↑ Summary DocumentsList/Role/Exportable.pm »