blib/lib/WebService/Bugzilla/Attachment.pm

filter: Statementstmt 55.3% 36 / 65 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 45.4% 5 / 11 Podpod 100% 3 / 3 totaltotal 44.0% 44 / 100 CC 9 SCAR 25.9
CC
9
Cov
44%
search
30.0
get
20.0
__ANON__
6.0
CRAP 13.3
« lib/WebService/Bugzilla.pm ↑ Summary blib/lib/WebService/Bugzilla/User.pm »
1 #!/usr/bin/false
2 # ABSTRACT: Bugzilla Attachment object and service
3 # PODNAME: WebService::Bugzilla::Attachment
4  
5 package WebService::Bugzilla::Attachment 0.001;
6 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 extends 'WebService::Bugzilla::Object';
12 1 with 'WebService::Bugzilla::Role::Updatable';
13  
14 0 ▶sub _unwrap_key { 'attachments' }
Subroutine _unwrap_key: not called CC=1 SCAR=6.9
15  
16 1 has bug_id => (is => 'ro', lazy => 1, builder => '_build_bug_id');
17 1 has content_type => (is => 'ro', lazy => 1, builder => '_build_content_type');
18 1 has creation_time => (is => 'ro', lazy => 1, builder => '_build_creation_time');
19 1 has creator => (is => 'ro', lazy => 1, builder => '_build_creator');
20 1 has description => (is => 'ro', lazy => 1, builder => '_build_description');
21 1 has filename => (is => 'ro', lazy => 1, builder => '_build_filename');
22 1 has is_obsolete => (is => 'ro', lazy => 1, builder => '_build_is_obsolete');
23 1 has is_patch => (is => 'ro', lazy => 1, builder => '_build_is_patch');
24 1 has is_private => (is => 'ro', lazy => 1, builder => '_build_is_private');
25 1 has last_change_time => (is => 'ro', lazy => 1, builder => '_build_last_change_time');
26 1 has size => (is => 'ro', lazy => 1, builder => '_build_size');
27  
28 0 ▶around BUILDARGS => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
29 0 my ($orig, $class, @args) = @_;
30 0 my $args = $class->$orig(@args);
31 0 ▶ if (exists $args->{file_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"file_name"}) 0 0 0
32 0 $args->{filename} = delete $args->{file_name};
33 }
34 0 return $args;
35 1 };
36  
37 1 my @attrs = qw(
38 bug_id
39 content_type
40 creation_time
41 creator
42 description
43 filename
44 is_obsolete
45 is_patch
46 is_private
47 last_change_time
48 size
49 );
50  
51 1 for my $attr (@attrs) {
52 11 my $build = "_build_$attr";
53 {
54 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 11 ▶ *{ $build } = sub {
Subroutine __ANON__: not called CC=1 SCAR=3.5
56 0 my ($self) = @_;
57 0 $self->_fetch_full($self->_mkuri('attachment/' . $self->id));
58 0 return $self->_api_data->{$attr};
59 11 };
60 }
61 }
62  
63 0 ▶sub create {
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
64 0 my ($self, $bug_id, %params) = @_;
65 0 my $res = $self->client->post($self->_mkuri("bug/$bug_id/attachment"), \%params);
66 return $self->new(
67 client => $self->client,
68 0 _data => { id => $res->{ids}[0], bug_id => $bug_id },
69 );
70 }
71  
72 0 ▶sub get {
Subroutine get: not called CC=4 SCAR=30.0
Pod documented
73 0 my ($self, $id) = @_;
74 0 my $res = $self->client->get($self->_mkuri("attachment/$id"));
75 0 ▶ return unless $res->{attachments} && @{ $res->{attachments} };
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"attachments"} and @{$res->{"attachments"};} 0 0 0
Condition0%0/3
$res->{"attachments"} and @{$res->{"attachments"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$res->{"attachments"} and @{$res->{"attachments"};}
$res->{"attachments"} @{$res->{"attachments"};}
Truth table0%0/3
A and B
A= $res->{"attachments"}B= @{$res->{"attachments"};}
ABresult
0X0
100
111
76 0 my $data = $res->{attachments}[0];
77 0 ▶ if (exists $data->{file_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"file_name"}) 0 0 0
78 0 $data->{filename} = delete $data->{file_name};
79 }
80 0 return $self->new(
81 client => $self->client,
82 _data => $data,
83 );
84 }
85  
86 0 ▶sub search {
Subroutine search: not called CC=5 SCAR=34.0
Pod documented
87 0 my ($self, %params) = @_;
88 0 ▶ my $bug_id = $params{bug_id} // croak 'bug_id is required for attachment search';
Condition0%0/2
$params{"bug_id"} // croak("bug_id is required for attachment search")
l!l
00
MC/DC0%0/1
$params{"bug_id"} // croak("bug_id is required for attachment search")
$params{"bug_id"}
Truth table0%0/2
A
A= $params{"bug_id"}
Aresult
11
00
89 0 my $res = $self->client->get($self->_mkuri("bug/$bug_id/attachment"));
90 return [
91 map {
92 0 my $data = $_;
93 0 ▶ if (exists $data->{file_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"file_name"}) 0 0 0
94 0 $data->{filename} = delete $data->{file_name};
95 }
96 $self->new(
97 0 client => $self->client,
98 _data => $data
99 )
100 }
101 0 ▶ @{ ($res->{bugs} // {})->{"$bug_id"} // [] }
Condition0%0/4
($res->{"bugs"} // {})->{"$bug_id"} // []
l!l
00
$res->{"bugs"} // {}
l!l
00
MC/DC0%0/1
($res->{"bugs"} // {})->{"$bug_id"} // []
$res->{"bugs"}
Truth table0%0/2
A
A= $res->{"bugs"}
Aresult
11
00
102 ];
103 }
104  
105 1 1;
106  
107 __END__
« lib/WebService/Bugzilla.pm ↑ Summary blib/lib/WebService/Bugzilla/User.pm »