DAV/XML.pm

filter: Statementstmt 96.4% 82 / 85 Branchbran 73.0% 19 / 26 Conditioncond 44.4% 8 / 18 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 89.4% 17 / 19 Podpod 37.5% 3 / 8 totaltotal 78.4% 131 / 167 CC 22 SCAR 22.4
CC
22
Cov
84%
__ANON__
23.6
maybe_invoke
3.0
__ANON__
2.0
CRAP 9.4
« DAV.pm ↑ Summary DAV/Response.pm »
1 package Net::Async::HTTP::DAV::XML;
2 4 $Net::Async::HTTP::DAV::XML::VERSION = '0.001';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use parent qw(XML::SAX::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Date::Parse qw(str2time);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 my %handler = (
11 'D:response' => {
12 3 ▶ start => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
13 3 my ($self, $tag, $data) = @_;
14 3 $self->{item} = {};
15 },
16 3 ▶ end => sub {
Subroutine __ANON__: called CC=14 SCAR=31.6
17 3 my ($self, $tag, $data) = @_;
18 3 my $item = $self->{item};
19 3 ▶ $item->{modified} ||= str2time(delete $item->{lastmodifieddate}) if exists $item->{lastmodifieddate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $item->{"lastmodifieddate"} 3 0 3
Condition33%1/3
$item->{"modified"} ||= str2time(delete $item->{"lastmodifieddate"})
l!l&&r!l&&!r
030
MC/DC0%0/2
$item->{"modified"} ||= str2time(delete $item->{"lastmodifieddate"})
$item->{"modified"} str2time(delete $item->{"lastmodifieddate"})
Truth table33%1/3
A ||= B
A= $item->{"modified"}B= str2time(delete $item->{"lastmodifieddate"})
ABresult
1X1
011
000
20 3 ▶ $item->{modified} ||= str2time(delete $item->{getlastmodifieddate}) if exists $item->{getlastmodifieddate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $item->{"getlastmodifieddate"} 0 3 3
Condition0%0/3
$item->{"modified"} ||= str2time(delete $item->{"getlastmodifieddate"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$item->{"modified"} ||= str2time(delete $item->{"getlastmodifieddate"})
$item->{"modified"} str2time(delete $item->{"getlastmodifieddate"})
Truth table0%0/3
A ||= B
A= $item->{"modified"}B= str2time(delete $item->{"getlastmodifieddate"})
ABresult
1X1
011
000
21 3 ▶ $item->{modified} ||= str2time(delete $item->{getlastmodified}) if exists $item->{getlastmodified};
Branch: 1 branch
BranchTrueFalseTotal
if exists $item->{"getlastmodified"} 3 0 3
Condition33%1/3
$item->{"modified"} ||= str2time(delete $item->{"getlastmodified"})
l!l&&r!l&&!r
300
MC/DC0%0/2
$item->{"modified"} ||= str2time(delete $item->{"getlastmodified"})
$item->{"modified"} str2time(delete $item->{"getlastmodified"})
Truth table33%1/3
A ||= B
A= $item->{"modified"}B= str2time(delete $item->{"getlastmodified"})
ABresult
1X1
011
000
22 3 ▶ $item->{size} = delete $item->{getcontentlength} if exists $item->{getcontentlength};
Branch: 1 branch
BranchTrueFalseTotal
if exists $item->{"getcontentlength"} 1 2 3
23 3 ▶ $item->{type} = ((delete $item->{resourcetype}) // '' eq 'collection') ? 'directory' : 'file';
Branch: 1 branch
BranchTrueFalseTotal
delete $item->{'resourcetype'} // !1 ? : 2 1 3
Condition50%1/2
delete $item->{"resourcetype"} //
l!l
30
MC/DC0%0/1
delete $item->{"resourcetype"} //
delete $item->{"resourcetype"}
Truth table50%1/2
A
A= delete $item->{"resourcetype"}
Aresult
11
00
24 3 ▶ $item->{path} = delete $item->{href} if exists $item->{href};
Branch: 1 branch
BranchTrueFalseTotal
if exists $item->{"href"} 3 0 3
25 3 ▶ $item->{displayname} = '.' if $item->{path} eq ($self->{path} // '');
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"path"} eq ($self->{"path"} // "") 0 3 3
Condition50%1/2
$self->{"path"} // ""
l!l
03
MC/DC0%0/1
$self->{"path"} // ""
$self->{"path"}
Truth table50%1/2
A
A= $self->{"path"}
Aresult
11
00
26 3 ▶ ($item->{displayname}) = $item->{path} =~ m{([^/]+)$} unless defined $item->{displayname};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item->{"displayname"} 0 3 3
27 3 $self->maybe_invoke('on_item', $item);
28 3 delete $self->{item};
29 },
30 },
31 'D:multistatus' => {
32 1 ▶ end => sub { my ($self, $tag, $data) = @_; $self->maybe_invoke('on_complete'); }
Subroutine __ANON__: called CC=1 SCAR=0.0
33 },
34 'D:collection' => {
35 2 ▶ start => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
36 2 my ($self, $tag, $data) = @_;
37 2 (my $name = $tag->{Name}) =~ s/^D://;
38 2 ▶ $self->{item}->{resourcetype} = $name if $self->{stack}[1]{Name} eq 'D:resourcetype';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stack"}[1]{"Name"} eq "D:resourcetype" 2 0 2
39 }
40 },
41 4 );
42  
43 4 foreach my $type (qw(
44 creationdate
45 getlastmodified
46 getetag
47 displayname
48 getcontentlanguage
49 getcontentlength
50 getcontenttype
51 immutable
52 lastmodifieddate
53 resourceid
54 resourcetype
55 src
56 dst
57 read-only
58 href
59 )) {
60 $handler{"lp1:$type"} = $handler{"D:$type"} = {
61 34 ▶ start => sub { my $self = shift; $self->{item}->{$type} = ''; },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 34 ▶ end => sub { my $self = shift; $self->maybe_invoke('on_item_property', $self->{item}, $type, $self->{item}->{$type}); },
Subroutine __ANON__: called CC=1 SCAR=0.0
63 29 ▶ content => sub { my $self = shift; $self->{item}->{$type} .= $_[0]; },
Subroutine __ANON__: called CC=1 SCAR=0.0
64 60 };
65 }
66  
67  
68 1 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
69 1 my $class = shift;
70 1 my %args = @_;
71 1 my $self = $class->SUPER::new(@_);
72 1 $self->{$_} = delete $args{$_} for grep { /^on_/ } keys %args;
73 1 $self->{dav} = delete $args{dav};
74 1 $self->{href} = delete $args{href};
75 1 $self->{stack} = [];
76 1 return $self;
77 }
78  
79 0 ▶sub dav { shift->{dav} }
Subroutine dav: not called CC=1 SCAR=6.9
Pod undocumented
80  
81 0 ▶sub debug {
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
82 0 my $self = shift;
83 0 $self->dav->debug(@_);
84 }
85  
86 =head2 start_element
87  
88 =cut
89  
90 49 ▶sub start_element {
Subroutine start_element: called CC=2 SCAR=6.9
Pod documented
91 49 my $self = shift;
92 49 my $element = shift;
93 49 unshift @{$self->{stack}}, $element;
94 49 ▶ if(my $handler = $handler{$element->{Name}}->{start}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $handler{$element->{"Name"}}{"start"}) 39 10 49
95 39 $handler->($self, $element);
96 39 return $self->SUPER::start_element($element);
97 }
98  
99 # Find an appropriate class for this element
100 10 my $v = $element->{Name};
101 # warn "Had unhandled $v\n";
102 10 return $self->SUPER::start_element($element);
103 }
104  
105 =head2 end_element
106  
107 =cut
108  
109 49 ▶sub end_element {
Subroutine end_element: called CC=2 SCAR=6.9
Pod documented
110 49 my $self = shift;
111 49 my $element = shift;
112 49 shift @{$self->{stack}};
113 49 ▶ if(my $handler = $handler{$element->{Name}}->{end}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $handler{$element->{"Name"}}{"end"}) 38 11 49
114 38 $handler->($self);
115 38 return $self->SUPER::end_element($element);
116 }
117 11 return $self->SUPER::end_element($element);
118 }
119  
120 =head2 characters
121  
122 =cut
123  
124 88 ▶sub characters {
Subroutine characters: called CC=2 SCAR=6.9
Pod documented
125 88 my $self = shift;
126 88 my $element = $self->{stack}->[0];
127 88 ▶ if(my $handler = $handler{$element->{Name}}->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $handler{$element->{"Name"}}{"content"}) 29 59 88
128 29 $handler->($self, $_[0]->{Data});
129 29 return $self->SUPER::characters(@_);
130 }
131 59 return $self->SUPER::characters(@_);
132 }
133  
134 34 ▶sub on_item_property {
Subroutine on_item_property: called CC=2 SCAR=7.1
Pod undocumented
135 34 my $self = shift;
136 34 my ($item, $k, $v) = @_;
137 34 ▶ $v //= '';
Condition50%1/2
$v //= ""
l!l
034
MC/DC0%0/1
$v //= ""
$v
Truth table50%1/2
A
A= $v
Aresult
11
00
138 # warn " $k => $v\n";
139 }
140  
141 38 ▶sub maybe_invoke {
Subroutine maybe_invoke: called CC=3 SCAR=11.0
Pod undocumented
142 38 my $self = shift;
143 38 my $type = shift;
144 38 ▶ my $code = $self->{$type} || $self->can($type);
Condition100%3/3
$self->{$type} || $self->can($type)
l!l&&r!l&&!r
3341
MC/DC100%2/2
$self->{$type} || $self->can($type)
$self->{$type} $self->can($type)
Truth table100%3/3
A || B
A= $self->{$type}B= $self->can($type)
ABresult
1X1
011
000
145 38 ▶ return unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 1 37 38
146 37 return $code->(@_);
147 }
148  
149 4 1;
150  
151 __END__
« DAV.pm ↑ Summary DAV/Response.pm »