Gnip/Publisher.pm

filter: Statementstmt 100% 36 / 36 Branchbran 75.0% 3 / 4 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 84.1% 53 / 63 CC 8 SCAR 10.9
CC
8
Cov
88%
_from_element
4.4
as_xml
4.0
new
2.0
CRAP 3.0
« Gnip/BaseStream.pm ↑ Summary Gnip/Base.pm »
1 package Net::Gnip::Publisher;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use base qw(Net::Gnip::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 <name>
30  
31 Initializes a Net::Gnip::Publisher object
32  
33 =cut
34  
35 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
36 4 my $class = shift;
37 4 ▶ my $name = shift || die "You must pass in a name";
Condition50%1/2
shift() || die('You must pass in a name')
l!l
40
MC/DC0%0/1
shift() || die('You must pass in a name')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
38 4 my %opts = @_;
39 4 $opts{name} = $name;
40 4 return bless \%opts, $class;
41 }
42  
43 =head2 name [name]
44  
45 Get or set the name
46  
47 =cut
48 4 ▶sub name { shift->_do('name', @_) }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
49  
50 =head2 parse <xml>
51  
52 Parse some xml into an activity.
53  
54 =cut
55  
56 1 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod documented
57 1 my $class = shift;
58 1 my $xml = shift;
59 1 my %opts = @_;
60 1 my $parser = $class->parser();
61 1 my $doc = $parser->parse_string($xml);
62 1 my $elem = $doc->documentElement();
63 1 return $class->_from_element($elem, %opts);
64 }
65  
66 2 ▶sub _from_element {
Subroutine _from_element: called CC=4 SCAR=14.8
67 2 my $class = shift;
68 2 my $elem = shift;
69 2 my %opts = @_;
70 2 ▶ my $no_dt = (ref($class) && $class->{_no_dt}) || $opts{_no_dt};
Condition33%2/6
ref $class && $class->{'_no_dt'} || $opts{'_no_dt'}
l!l&&r!l&&!r
002
ref $class and $class->{"_no_dt"}
!ll&&!rl&&r
200
MC/DC0%0/3
ref $class && $class->{'_no_dt'} || $opts{'_no_dt'}
ref $class $class->{"_no_dt"} $opts{'_no_dt'}
Truth table20%1/5
A and B || C
A= ref $classB= $class->{"_no_dt"}C= $opts{'_no_dt'}
ABCresult
11X1
0X11
1011
0X00
1000
71 2 foreach my $attr ($elem->attributes()) {
72 2 my $name = $attr->name;
73 2 $opts{$name} = $attr->value;
74 }
75 2 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 2 ▶sub as_xml {
Subroutine as_xml: called CC=4 SCAR=13.9
Pod documented
85 2 my $self = shift;
86 2 my $as_element = shift;
87 2 my $element = XML::LibXML::Element->new('publisher');
88 2 foreach my $key (keys %$self) {
89 2 ▶ next if '_' eq substr($key, 0, 1);
Branch: 1 branch
BranchTrueFalseTotal
if "_" eq substr($key, 0, 1) 0 2 2
90 2 my $value = $self->{$key};
91 2 $element->setAttribute($key, $value);
92 }
93 2 ▶ return ($as_element) ? $element : $element->toString(1);
Branch: 1 branch
BranchTrueFalseTotal
$as_element ? : 1 1 2
94 }
95  
96 7 1;
« Gnip/BaseStream.pm ↑ Summary Gnip/Base.pm »