blib/lib/XML/Loy/Atom/Threading.pm

filter: Statementstmt 96.3% 53 / 55 Branchbran 75.0% 21 / 28 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 85.5% 89 / 104 CC 17 SCAR 16.6
CC
17
Cov
86%
replies
7.4
total
6.3
in_reply_to
6.0
CRAP 5.3
« blib/lib/XML/Loy/Atom.pm ↑ Summary blib/lib/XML/Loy/XRD.pm »
1 package XML::Loy::Atom::Threading;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $PREFIX;
6 3 ▶BEGIN { $PREFIX = 'thr' };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use XML::Loy with => (
Subroutine BEGIN: called CC=1 SCAR=0.0
9 prefix => $PREFIX,
10 namespace => 'http://purl.org/syndication/thread/1.0'
11 3 );
12  
13 3 ▶use Carp qw/carp/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # No constructor
17 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
18 1 carp 'Only use ' . __PACKAGE__ . ' as an extension to Atom';
19 1 return;
20 };
21  
22  
23 # Set 'in-reply-to' element
24 10 ▶sub in_reply_to {
Subroutine in_reply_to: called CC=6 SCAR=18.0
Pod documented
25 10 my ($self, $ref, $param) = @_;
26  
27 # Add in-reply-to
28 10 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 4 6 10
29  
30 # No ref defined
31 4 ▶ return unless defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 4 4
32  
33 # Adding a related link as advised in the spec
34 4 ▶ if (defined $param->{href}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param->{"href"}) 4 0 4
35 4 my $link = $self->link(related => $param->{href});
36 4 ▶ $link->attr->{type} = $param->{type} if $param->{type};
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"type"} 2 2 4
37 };
38  
39 4 $param->{ref} = $ref;
40 4 return $self->add('in-reply-to' => $param );
41 };
42  
43 # Current node is root
44 6 ▶ unless ($self->parent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->parent) 2 4 6
45 2 return $self->at('*')->children('in-reply-to');
46 };
47  
48 # Return collection
49 4 return $self->children('in-reply-to');
50 };
51  
52  
53 # Add 'link' element for replies
54 6 ▶sub replies {
Subroutine replies: called CC=7 SCAR=20.0
Pod documented
55 6 my $self = shift;
56 6 my $href = shift;
57  
58 # Add link
59 6 ▶ if ($href) {
Branch: 1 branch
BranchTrueFalseTotal
if ($href) 3 3 6
60  
61 3 my %param = %{ shift(@_) };
62  
63 3 my %new_param = (href => $href);
64 3 ▶ if (exists $param{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{"count"}) 3 0 3
65 3 $new_param{$PREFIX . ':count'} = delete $param{count};
66 };
67  
68 # updated parameter exists
69 3 ▶ if (exists $param{updated}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{"updated"}) 2 1 3
70 2 my $date = delete $param{updated};
71  
72 # Date is no object
73 2 ▶ $date = XML::Loy::Date::RFC3339->new($date) unless ref $date;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $date 2 0 2
74  
75 # Set parameter
76 2 $new_param{$PREFIX . ':updated'} = $date->to_string;
77 };
78  
79 3 ▶ $new_param{type} = $param{type} // $self->mime;
Condition33%1/3
$param{"type"} // $self->mime
l!l&&r!l&&!r
030
MC/DC0%0/2
$param{"type"} // $self->mime
$param{"type"} $self->mime
Truth table33%1/3
A // B
A= $param{"type"}B= $self->mime
ABresult
1X1
011
000
80  
81 # Add atom link
82 3 return $self->link(rel => 'replies', %new_param );
83 };
84  
85 # Get replies
86 3 my $replies = $self->link('replies');
87  
88 # Return first link
89 3 ▶ return $replies->[0] if $replies->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $replies->[0] 3 0 3
90  
91 0 return;
92 };
93  
94  
95 # Add total value
96 10 ▶sub total {
Subroutine total: called CC=6 SCAR=18.4
Pod documented
97 10 my ($self, $count, $param) = @_;
98  
99 # Set count
100 10 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 5 5 10
101  
102 # Set new total element
103 5 ▶ return $self->set(total => ($param || {}) => $count);
Condition50%1/2
$param || {}
l!l
05
MC/DC0%0/1
$param || {}
$param
Truth table50%1/2
A
A= $param
Aresult
11
00
104 };
105  
106 # Get total
107 5 my $total;
108  
109 # Current node is root
110 5 ▶ unless ($self->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent) { } 4 1 5
111 1 $total = $self->at('*')->children('total');
112 }
113  
114 # Current node is entry or something
115 else {
116 4 $total = $self->children('total');
117 };
118  
119 # No total set
120 5 ▶ return 0 unless $total = $total->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $total = $total->[0] 0 5 5
121  
122 # Return count
123 5 ▶ return $total->text if $total->text;
Branch: 1 branch
BranchTrueFalseTotal
if $total->text 5 0 5
124  
125 0 return 0;
126 };
127  
128  
129 3 1;
130  
131  
132 __END__
« blib/lib/XML/Loy/Atom.pm ↑ Summary blib/lib/XML/Loy/XRD.pm »