| 1 | package Net::Google::DocumentsList::Role::HasItems; | ||||||||||||||||||
| 2 | 14 | ▶ | use Any::Moose '::Role'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | 14 | with 'Net::Google::DocumentsList::Role::EnsureListed'; | |||||||||||||||||
| 4 | 14 | ▶ | use Net::Google::DataAPI; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 14 | ▶ | use URI; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 14 | ▶ | use MIME::Types; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 14 | ▶ | use File::stat; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 14 | ▶ | use Carp 'confess'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 14 | requires 'items', 'item', 'add_item'; | |||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | 0 | ▶ | around items => sub { | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||
| 13 | 0 | my ($next, $self, $cond) = @_; | |||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 0 | my @items; | |||||||||||||||||
| 16 | 0 | ▶ | if (my $resource_id = delete $cond->{resource_id}) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 17 | 0 | ▶ | my $atom = eval {$self->service->get_entry( | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 18 | join('/', $self->service->item_feedurl, $resource_id) | ||||||||||||||||||
| 19 | )} or return; | ||||||||||||||||||
| 20 | 0 | my $class = $self->item_entryclass; | |||||||||||||||||
| 21 | 0 | Any::Moose::load_class($class); | |||||||||||||||||
| 22 | 0 | ▶ | @items = $class->new( | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 23 | $self->can('sync') ? (container => $self) : (service => $self), | ||||||||||||||||||
| 24 | atom => $atom, | ||||||||||||||||||
| 25 | ); | ||||||||||||||||||
| 26 | } elsif (my $cats = delete $cond->{category}) { | ||||||||||||||||||
| 27 | 0 | ▶ | $cats = [ "$cats" ] unless ref $cats eq 'ARRAY'; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 28 | 0 | @items = $self->items_with_category('item', $cats, $cond); | |||||||||||||||||
| 29 | } else { | ||||||||||||||||||
| 30 | 0 | @items = $next->($self, $cond); | |||||||||||||||||
| 31 | } | ||||||||||||||||||
| 32 | 0 | ▶ | if ($self->can('sync')) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 33 | 0 | @items = grep {$_->parent eq $self->_url_with_resource_id} @items; | |||||||||||||||||
| 34 | } | ||||||||||||||||||
| 35 | 0 | @items; | |||||||||||||||||
| 36 | 14 | }; | |||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 0 | ▶ | sub items_with_category { | ||||||||||||||||
|
Subroutine
items_with_category: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||
| 39 | 0 | my ($self, $method, $cats, $cond) = @_; | |||||||||||||||||
| 40 | 0 | my $feedurl = $self->can($method.'_feedurl'); | |||||||||||||||||
| 41 | 0 | my $entryclass = $self->can($method.'_entryclass'); | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 0 | my $uri = URI->new_abs( | |||||||||||||||||
| 44 | join('/','-', @$cats), | ||||||||||||||||||
| 45 | $feedurl->($self). '/', | ||||||||||||||||||
| 46 | ); | ||||||||||||||||||
| 47 | 0 | my $feed = $self->service->get_feed($uri, $cond); | |||||||||||||||||
| 48 | 0 | my $class = $entryclass->($self); | |||||||||||||||||
| 49 | 0 | Any::Moose::load_class($class); | |||||||||||||||||
| 50 | return map { | ||||||||||||||||||
| 51 | 0 | ▶ | $class->new( | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 52 | $self->can('sync') ? (container => $self) : (service => $self), | ||||||||||||||||||
| 53 | atom => $_, | ||||||||||||||||||
| 54 | ); | ||||||||||||||||||
| 55 | } $feed->entries; | ||||||||||||||||||
| 56 | } | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | 0 | ▶ | around add_item => sub { | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=17 SCAR=57.2
| |||||||||||||||||||
| 59 | 0 | my ($next, $self, $args) = @_; | |||||||||||||||||
| 60 | 0 | my $item; | |||||||||||||||||
| 61 | 0 | ▶ | if (my $file = delete $args->{file}) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 62 | 0 | ▶ | -r $file or confess "File $file does not exist"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 63 | 0 | ▶ | my $stat = stat($file) or confess "can not stat file $file"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 64 | 0 | my $size = $stat->size; | |||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | 0 | ▶ | my $convert = delete $args->{convert} || 'true'; | ||||||||||||||||
|
Condition0%0/2
delete $args->{'convert'} || 'true'
MC/DC0%0/1
delete $args->{'convert'} || 'true'
delete $args->{'convert'}
Truth table0%0/2
A
A= delete $args->{'convert'}
| |||||||||||||||||||
| 67 | 0 | my $source_lang = delete $args->{source_language}; | |||||||||||||||||
| 68 | 0 | my $target_lang = delete $args->{target_language}; | |||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | 0 | ▶ | my $ct = MIME::Types->new->mimeTypeOf($file)->type || 'application/octet-stream'; | ||||||||||||||||
|
Condition0%0/2
'MIME::Types'->new->mimeTypeOf($file)->type || 'application/octet-stream'
MC/DC0%0/1
'MIME::Types'->new->mimeTypeOf($file)->type || 'application/octet-stream'
'MIME::Types'->new->mimeTypeOf($file)->type
Truth table0%0/2
A
A= 'MIME::Types'->new->mimeTypeOf($file)->type
| |||||||||||||||||||
| 71 | 0 | ▶ | open my $fh, '<:bytes', $file or confess "file $file could not be opened"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | 0 | my $class = $self->item_entryclass; | |||||||||||||||||
| 74 | 0 | Any::Moose::load_class($class); | |||||||||||||||||
| 75 | 0 | ▶ | my $entry = $class->new( | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 76 | $self->can('sync') ? (container => $self) : (service => $self), | ||||||||||||||||||
| 77 | %$args, | ||||||||||||||||||
| 78 | )->to_atom; | ||||||||||||||||||
| 79 | |||||||||||||||||||
| 80 | 0 | my ($link) = map {$_->href} | |||||||||||||||||
| 81 | 0 | grep {$_->rel eq 'http://schemas.google.com/g/2005#resumable-create-media'} | |||||||||||||||||
| 82 | $self->service->get_feed($self->item_feedurl)->link; | ||||||||||||||||||
| 83 | 0 | ▶ | my $res = $self->service->request( | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 84 | { | ||||||||||||||||||
| 85 | uri => $link, | ||||||||||||||||||
| 86 | content_type => 'application/atom+xml', | ||||||||||||||||||
| 87 | header => { | ||||||||||||||||||
| 88 | 'X-Upload-Content-Type' => $ct, | ||||||||||||||||||
| 89 | 'X-Upload-Content-Length' => $size, | ||||||||||||||||||
| 90 | }, | ||||||||||||||||||
| 91 | query => { | ||||||||||||||||||
| 92 | $convert eq 'false' ? (convert => 'false') : (), | ||||||||||||||||||
| 93 | $source_lang ? (sourceLanguage => $source_lang) : (), | ||||||||||||||||||
| 94 | $target_lang ? (targetLanguage => $target_lang) : (), | ||||||||||||||||||
| 95 | }, | ||||||||||||||||||
| 96 | content => $entry->as_xml, | ||||||||||||||||||
| 97 | } | ||||||||||||||||||
| 98 | ); | ||||||||||||||||||
| 99 | 0 | my $atom; | |||||||||||||||||
| 100 | 0 | ▶ | if ($res->is_success) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 101 | 0 | my $uri = $res->header('Location'); | |||||||||||||||||
| 102 | 0 | my $offset = 0; | |||||||||||||||||
| 103 | 0 | ▶ | while (my $length = read $fh, my $part, 512*1024) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 104 | 0 | my $req = HTTP::Request->new(PUT => $uri); | |||||||||||||||||
| 105 | 0 | $req->content_type($ct); | |||||||||||||||||
| 106 | 0 | $req->content_length($length); | |||||||||||||||||
| 107 | 0 | $req->header('Content-Range' => sprintf('bytes %d-%d/%d', $offset, $offset + $length - 1, $size)); | |||||||||||||||||
| 108 | 0 | $req->content($part); | |||||||||||||||||
| 109 | 0 | my $res = $self->service->request($req); | |||||||||||||||||
| 110 | 0 | ▶ | if ($res->code == 201) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 111 | 0 | $atom = XML::Atom::Entry->new(\($res->content)); | |||||||||||||||||
| 112 | 0 | last; | |||||||||||||||||
| 113 | } else { | ||||||||||||||||||
| 114 | 0 | ▶ | if (my $next = $res->header('Location')) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 115 | 0 | $uri = $next; | |||||||||||||||||
| 116 | } | ||||||||||||||||||
| 117 | } | ||||||||||||||||||
| 118 | 0 | $offset = $offset + $length; | |||||||||||||||||
| 119 | } | ||||||||||||||||||
| 120 | } | ||||||||||||||||||
| 121 | 0 | ▶ | $self->sync if $self->can('sync'); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 122 | 0 | ▶ | $item = $class->new( | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 123 | $self->can('sync') ? (container => $self) : (service => $self), | ||||||||||||||||||
| 124 | atom => $atom, | ||||||||||||||||||
| 125 | ); | ||||||||||||||||||
| 126 | } else { | ||||||||||||||||||
| 127 | 0 | $item = $next->($self, $args); | |||||||||||||||||
| 128 | } | ||||||||||||||||||
| 129 | 0 | return $self->ensure_listed($item, {etag_should_change => 1}); | |||||||||||||||||
| 130 | 14 | }; | |||||||||||||||||
| 131 | |||||||||||||||||||
| 132 | 0 | ▶ | sub add_folder { | ||||||||||||||||
|
Subroutine
add_folder: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||
| 133 | 0 | my ($self, $args) = @_; | |||||||||||||||||
| 134 | return $self->add_item( | ||||||||||||||||||
| 135 | { | ||||||||||||||||||
| 136 | 0 | ▶ | %{$args || {}}, | ||||||||||||||||
|
Condition0%0/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||
| 137 | kind => 'folder', | ||||||||||||||||||
| 138 | } | ||||||||||||||||||
| 139 | ); | ||||||||||||||||||
| 140 | } | ||||||||||||||||||
| 141 | |||||||||||||||||||
| 142 | 0 | ▶ | sub folders { | ||||||||||||||||
|
Subroutine
folders: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||
| 143 | 0 | my ($self, $args) = @_; | |||||||||||||||||
| 144 | 0 | ▶ | my $cat = delete $args->{category} || []; | ||||||||||||||||
|
Condition0%0/2
delete $args->{'category'} || []
MC/DC0%0/1
delete $args->{'category'} || []
delete $args->{'category'}
Truth table0%0/2
A
A= delete $args->{'category'}
| |||||||||||||||||||
| 145 | 0 | ▶ | $cat = [ $cat ] unless ref $cat; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 146 | return $self->items( | ||||||||||||||||||
| 147 | { | ||||||||||||||||||
| 148 | 0 | ▶ | %{$args || {}}, | ||||||||||||||||
|
Condition0%0/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||
| 149 | category => [ 'folder', @$cat ], | ||||||||||||||||||
| 150 | } | ||||||||||||||||||
| 151 | ); | ||||||||||||||||||
| 152 | } | ||||||||||||||||||
| 153 | |||||||||||||||||||
| 154 | 0 | ▶ | sub folder { | ||||||||||||||||
|
Subroutine
folder: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 155 | 0 | my ($self, $args) = @_; | |||||||||||||||||
| 156 | 0 | return [ $self->folders($args) ]->[0]; | |||||||||||||||||
| 157 | } | ||||||||||||||||||
| 158 | |||||||||||||||||||
| 159 | 14 | 1; | |||||||||||||||||
| 160 | __END__ | ||||||||||||||||||