line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Gnip::Activity::Payload; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
19054
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
161
|
|
4
|
3
|
|
|
3
|
|
17
|
use base qw(Net::Gnip::Base); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
507
|
|
5
|
|
|
|
|
|
|
use Carp qw(confess); |
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 [opt[s]] |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Create a new payload. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
sub new { |
29
|
|
|
|
|
|
|
my $class = shift; |
30
|
|
|
|
|
|
|
my $body = shift || confess "You must pass in a body\n"; |
31
|
|
|
|
|
|
|
my %opts = @_; |
32
|
|
|
|
|
|
|
$opts{body} ||= $body; |
33
|
|
|
|
|
|
|
return bless {%opts}, ref($class) || $class; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 body [body] |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Get or set the body of this payload. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
sub body { shift->_do('body', @_); } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 raw [raw] |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Get or set the raw of this payload. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
sub raw { shift->_do('raw', @_); } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 parse |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Takes a string of XML, parses it and returns a new, |
53
|
|
|
|
|
|
|
potentially populated payload |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
sub parse { |
57
|
|
|
|
|
|
|
my $class = shift; |
58
|
|
|
|
|
|
|
my $xml = shift; |
59
|
|
|
|
|
|
|
my %opts = @_; |
60
|
|
|
|
|
|
|
my $no_dt = (ref($class) && $class->{_no_dt}) || $opts{_no_dt}; |
61
|
|
|
|
|
|
|
my $parser = $class->parser; |
62
|
|
|
|
|
|
|
my $doc = $parser->parse_string($xml); |
63
|
|
|
|
|
|
|
my $elem = $doc->documentElement(); |
64
|
|
|
|
|
|
|
return $class->_from_element($elem); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _from_element { |
68
|
|
|
|
|
|
|
my $class = shift; |
69
|
|
|
|
|
|
|
my $elem = shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my %opts; |
72
|
|
|
|
|
|
|
foreach my $child ($elem->childNodes) { |
73
|
|
|
|
|
|
|
my $name = $child->nodeName; |
74
|
|
|
|
|
|
|
my $text = ($child->firstChild()) ? $child->firstChild()->textContent() : undef; |
75
|
|
|
|
|
|
|
next unless defined $text; |
76
|
|
|
|
|
|
|
$opts{$name} = $text; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
my $body = delete $opts{body} || return undef; |
79
|
|
|
|
|
|
|
return $class->new($body, %opts); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 as_xml |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Return this payload as xml |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub as_xml { |
89
|
|
|
|
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
my $as_element = shift; |
91
|
|
|
|
|
|
|
my $element = XML::LibXML::Element->new('payload'); |
92
|
|
|
|
|
|
|
foreach my $name (qw(body raw)) { |
93
|
|
|
|
|
|
|
next unless defined $self->{$name}; |
94
|
|
|
|
|
|
|
my $tmp = XML::LibXML::Element->new($name); |
95
|
|
|
|
|
|
|
$tmp->appendTextNode($self->{$name}); |
96
|
|
|
|
|
|
|
$element->addChild($tmp); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
return ($as_element) ? $element : $element->toString(1); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |