| 1 | package XML::Loy::Atom::Threading; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | our $PREFIX; | |||||||||||||||||||
| 6 | 2 | ▶ | BEGIN { $PREFIX = 'thr' }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | use XML::Loy with => ( | |||||||||||||||||||
| 9 | prefix => $PREFIX, | ||||||||||||||||||||
| 10 | namespace => 'http://purl.org/syndication/thread/1.0' | ||||||||||||||||||||
| 11 | 2 | ▶ | ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | ▶ | use Carp qw/carp/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | # No constructor | ||||||||||||||||||||
| 17 | sub new { | ||||||||||||||||||||
| 18 | 1 | ▶ | carp 'Only use ' . __PACKAGE__ . ' as an extension to Atom'; | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 19 | 1 | return; | |||||||||||||||||||
| 20 | }; | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # Set 'in-reply-to' element | ||||||||||||||||||||
| 24 | sub in_reply_to { | ||||||||||||||||||||
| 25 | 10 | ▶ | my ($self, $ref, $param) = @_; | ||||||||||||||||||
|
Subroutine
in_reply_to: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | # Add in-reply-to | ||||||||||||||||||||
| 28 | 10 | ▶ | if ($ref) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # No ref defined | ||||||||||||||||||||
| 31 | 4 | ▶ | return unless defined $ref; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | # Adding a related link as advised in the spec | ||||||||||||||||||||
| 34 | 4 | ▶ | if (defined $param->{href}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 4 | my $link = $self->link(related => $param->{href}); | |||||||||||||||||||
| 36 | 4 | ▶ | $link->attr->{type} = $param->{type} if $param->{type}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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 | sub replies { | ||||||||||||||||||||
| 55 | 6 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
replies: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||||||||||||
| 56 | 6 | my $href = shift; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | # Add link | ||||||||||||||||||||
| 59 | 6 | ▶ | if ($href) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 3 | my %param = %{ shift(@_) }; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 3 | my %new_param = (href => $href); | |||||||||||||||||||
| 64 | 3 | ▶ | if (exists $param{count}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 3 | $new_param{$PREFIX . ':count'} = delete $param{count}; | |||||||||||||||||||
| 66 | }; | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # updated parameter exists | ||||||||||||||||||||
| 69 | 3 | ▶ | if (exists $param{updated}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
MC/DC0%0/2
$param{"type"} // $self->mime
$param{"type"}
$self->mime
Truth table33%1/3
A // B
A= $param{"type"}B= $self->mime
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||
| 92 | }; | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | # Add total value | ||||||||||||||||||||
| 96 | sub total { | ||||||||||||||||||||
| 97 | 8 | ▶ | my ($self, $count, $param) = @_; | ||||||||||||||||||
|
Subroutine
total: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | # Set count | ||||||||||||||||||||
| 100 | 8 | ▶ | if ($count) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | # Set new total element | ||||||||||||||||||||
| 103 | 4 | ▶ | return $self->set(total => ($param || {}) => $count); | ||||||||||||||||||
|
Condition50%1/2
$param || {}
MC/DC0%0/1
$param || {}
$param
Truth table50%1/2
A
A= $param
| |||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | # Get total | ||||||||||||||||||||
| 107 | 4 | my $total; | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | # Current node is root | ||||||||||||||||||||
| 110 | 4 | ▶ | unless ($self->parent) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 1 | $total = $self->at('*')->children('total'); | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | # Current node is entry or something | ||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||
| 116 | 3 | $total = $self->children('total'); | |||||||||||||||||||
| 117 | }; | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | # No total set | ||||||||||||||||||||
| 120 | 4 | ▶ | return 0 unless $total = $total->[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | # Return count | ||||||||||||||||||||
| 123 | 4 | ▶ | return $total->text if $total->text; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | return 0; | |||||||||||||||||||
| 126 | }; | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 2 | 1; | |||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||