line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Gnip::Publisher; |
2
|
4
|
|
|
4
|
|
62280
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
170
|
|
3
|
4
|
|
|
4
|
|
24
|
use base qw(Net::Gnip::Base); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1325
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Net::Gnip::Publisher - represent a publisher |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $publisher = Net::Gnip::Publisher->new($name); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# ... or parse from xml |
15
|
|
|
|
|
|
|
my $publisher = Net::Gnip::Publisher->parse($xml); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Set the name |
18
|
|
|
|
|
|
|
$publisher->name($name); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Get the name |
21
|
|
|
|
|
|
|
my $name = $publisher->name |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
print $publisher->as_xml; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 new |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Initializes a Net::Gnip::Publisher object |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
|
|
|
|
|
|
my $class = shift; |
37
|
|
|
|
|
|
|
my $name = shift || die "You must pass in a name"; |
38
|
|
|
|
|
|
|
my %opts = @_; |
39
|
|
|
|
|
|
|
$opts{name} = $name; |
40
|
|
|
|
|
|
|
return bless \%opts, $class; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 name [name] |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Get or set the name |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
sub name { shift->_do('name', @_) } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 parse |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Parse some xml into an activity. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub parse { |
57
|
|
|
|
|
|
|
my $class = shift; |
58
|
|
|
|
|
|
|
my $xml = shift; |
59
|
|
|
|
|
|
|
my %opts = @_; |
60
|
|
|
|
|
|
|
my $parser = $class->parser(); |
61
|
|
|
|
|
|
|
my $doc = $parser->parse_string($xml); |
62
|
|
|
|
|
|
|
my $elem = $doc->documentElement(); |
63
|
|
|
|
|
|
|
return $class->_from_element($elem, %opts); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _from_element { |
67
|
|
|
|
|
|
|
my $class = shift; |
68
|
|
|
|
|
|
|
my $elem = shift; |
69
|
|
|
|
|
|
|
my %opts = @_; |
70
|
|
|
|
|
|
|
my $no_dt = (ref($class) && $class->{_no_dt}) || $opts{_no_dt}; |
71
|
|
|
|
|
|
|
foreach my $attr ($elem->attributes()) { |
72
|
|
|
|
|
|
|
my $name = $attr->name; |
73
|
|
|
|
|
|
|
$opts{$name} = $attr->value; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
return $class->new(delete $opts{name}, %opts, _no_dt => $no_dt); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 as_xml |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Return the activity as xml |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub as_xml { |
85
|
|
|
|
|
|
|
my $self = shift; |
86
|
|
|
|
|
|
|
my $as_element = shift; |
87
|
|
|
|
|
|
|
my $element = XML::LibXML::Element->new('publisher'); |
88
|
|
|
|
|
|
|
foreach my $key (keys %$self) { |
89
|
|
|
|
|
|
|
next if '_' eq substr($key, 0, 1); |
90
|
|
|
|
|
|
|
my $value = $self->{$key}; |
91
|
|
|
|
|
|
|
$element->setAttribute($key, $value); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
return ($as_element) ? $element : $element->toString(1); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |