| 1 | package Net::Gnip::Activity::Payload; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use base qw(Net::Gnip::Base); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | Net::Gnip::Activity::Payload - represent the payload in a Gnip activity item | ||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | my $payload = Net::Gnip::Activity::Payload->new($body); | ||||||||||||||||||||||||||||||||||||||
| 14 | $payload->raw($meta_data); | ||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | $activity->payload($payload); | ||||||||||||||||||||||||||||||||||||||
| 17 | my $payload = $activity->payload; | ||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | =head1 METHODS; | ||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | =head2 new <body> [opt[s]] | ||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | Create a new payload. | ||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 29 | 6 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | my $body = shift || confess "You must pass in a body\n"; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || confess("You must pass in a body\n")
MC/DC0%0/1
shift() || confess("You must pass in a body\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 31 | 6 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | $opts{body} ||= $body; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{"body"} ||= $body
MC/DC0%0/2
$opts{"body"} ||= $body
$opts{"body"}
$body
Truth table33%1/3
A ||= B
A= $opts{"body"}B= $body
| |||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | return bless {%opts}, ref($class) || $class; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | =head2 body [body] | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | Get or set the body of this payload. | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | sub body { shift->_do('body', @_); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | =head2 raw [raw] | ||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | Get or set the raw of this payload. | ||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub raw { shift->_do('raw', @_); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
raw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | =head2 parse <xml> | ||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||
| 52 | Takes a string of XML, parses it and returns a new, | ||||||||||||||||||||||||||||||||||||||
| 53 | potentially populated payload | ||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $xml = shift; | |||||||||||||||||||||||||||||||||||||
| 59 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $no_dt = (ref($class) && $class->{_no_dt}) || $opts{_no_dt}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
ref $class && $class->{'_no_dt'} || $opts{'_no_dt'}
ref $class and $class->{"_no_dt"}
MC/DC0%0/3
ref $class && $class->{'_no_dt'} || $opts{'_no_dt'}
ref $class
$class->{"_no_dt"}
$opts{'_no_dt'}
Truth table0%0/5
A and B || C
A= ref $classB= $class->{"_no_dt"}C= $opts{'_no_dt'}
| |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $parser = $class->parser; | |||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $doc = $parser->parse_string($xml); | |||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $elem = $doc->documentElement(); | |||||||||||||||||||||||||||||||||||||
| 64 | 0 | return $class->_from_element($elem); | |||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | sub _from_element { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_from_element: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||
| 68 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 69 | 4 | my $elem = shift; | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 4 | my %opts; | |||||||||||||||||||||||||||||||||||||
| 72 | 4 | foreach my $child ($elem->childNodes) { | |||||||||||||||||||||||||||||||||||||
| 73 | 8 | my $name = $child->nodeName; | |||||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | my $text = ($child->firstChild()) ? $child->firstChild()->textContent() : undef; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 75 | 8 | ▶ | next unless defined $text; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 76 | 4 | $opts{$name} = $text; | |||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||
| 78 | 4 | ▶ | my $body = delete $opts{body} || return undef; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opts{'body'} || (return undef)
MC/DC0%0/1
delete $opts{'body'} || (return undef)
delete $opts{'body'}
Truth table50%1/2
A
A= delete $opts{'body'}
| |||||||||||||||||||||||||||||||||||||||
| 79 | 4 | return $class->new($body, %opts); | |||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | =head2 as_xml | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | Return this payload as xml | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | sub as_xml { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
as_xml: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 89 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 90 | 2 | my $as_element = shift; | |||||||||||||||||||||||||||||||||||||
| 91 | 2 | my $element = XML::LibXML::Element->new('payload'); | |||||||||||||||||||||||||||||||||||||
| 92 | 2 | foreach my $name (qw(body raw)) { | |||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | next unless defined $self->{$name}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my $tmp = XML::LibXML::Element->new($name); | |||||||||||||||||||||||||||||||||||||
| 95 | 2 | $tmp->appendTextNode($self->{$name}); | |||||||||||||||||||||||||||||||||||||
| 96 | 2 | $element->addChild($tmp); | |||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | return ($as_element) ? $element : $element->toString(1); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 10 | 1; | |||||||||||||||||||||||||||||||||||||