Syndication/Thing.pm

filter: Statementstmt 92.7% 51 / 55 Branchbran 61.1% 11 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 80.2% 69 / 86 CC 12 SCAR 22.4
CC
12
Cov
83%
init
13.7
inner_atom
2.0
BEGIN
1.0
CRAP 9.4
« Syndication/Text.pm ↑ Summary Syndication/Writer.pm »
1 package XML::Atom::Syndication::Thing;
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 22 ▶use base qw( XML::Atom::Syndication::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 ▶use XML::Elemental;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 XML::Atom::Syndication::Thing->mk_accessors('XML::Atom::Syndication::Person',
10 'author', 'contributor');
11 22 XML::Atom::Syndication::Thing->mk_accessors('XML::Atom::Syndication::Link',
12 'link');
13 22 XML::Atom::Syndication::Thing->mk_accessors('XML::Atom::Syndication::Category',
14 'category');
15 22 XML::Atom::Syndication::Thing->mk_accessors('XML::Atom::Syndication::Text',
16 'rights', 'title');
17 22 XML::Atom::Syndication::Thing->mk_accessors('element', 'id', 'updated');
18  
19 202 ▶sub init {
Subroutine init: called CC=11 SCAR=26.2
Pod undocumented
20 202 my $thing = shift;
21 202 ▶ my %param = @_ == 1 ? (Stream => $_[0]) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 113 89 202
22 202 $thing->set_ns(\%param);
23 202 ▶ if (%param) {
Branch: 1 branch
BranchTrueFalseTotal
if (%param) { } 191 11 202
24 191 ▶ if (my $stream = $param{Stream}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $stream = $param{'Stream'}) { } 113 78 191
elsif ($param{'Elem'}) { } 78 0 78
25 113 my $parser = XML::Elemental->parser;
26 113 ▶ if (ref($stream) eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $stream eq 'SCALAR') { } 0 113 113
elsif (ref $stream eq 'GLOB' or not ref $stream) { } 113 0 113
27 0 $thing->{doc} = $parser->parse_string($$stream);
28 ▶ } elsif (ref $stream eq 'GLOB' || !ref($stream)) {
Condition33%1/3
ref $stream eq "GLOB" or not ref $stream
l!l&&r!l&&!r
11300
MC/DC0%0/2
ref $stream eq "GLOB" or not ref $stream
ref $stream eq "GLOB" not ref $stream
Truth table33%1/3
A or not(B)
A= ref $stream eq "GLOB"B= not ref $stream
ABresult
1X1
011
000
29 113 my $xml;
30 my $fh;
31 113 ▶ unless (ref $stream eq 'GLOB') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $stream eq 'GLOB') { } 113 0 113
32 0 $fh = gensym();
33 0 ▶ open $fh, $stream or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $stream or die $! 0 0 0
34 } else {
35 113 $fh = $stream;
36 }
37 113 { local $/; $xml = <$fh>; }
38 113 ▶ close $fh unless (ref $stream eq 'GLOB');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $stream eq "GLOB" 0 113 113
39 113 $thing->{doc} = $parser->parse_string($xml);
40 } else {
41 0 return;
42 }
43 113 $thing->{elem} = $thing->{doc}->contents->[0];
44 } elsif ($param{Elem}) {
45 78 $thing->{elem} = $param{Elem};
46 }
47 } else {
48 11 require XML::Elemental::Element;
49 11 $thing->{elem} = XML::Elemental::Element->new;
50 11 $thing->{elem}->name('{' . $thing->ns . '}' . $thing->element_name);
51 }
52 202 $thing;
53 }
54  
55 3 ▶sub inner_atom {
Subroutine inner_atom: called CC=2 SCAR=6.9
Pod undocumented
56 3 my ($thing, $str) = @_;
57 3 my $name = $thing->element_name;
58 3 my $ns = $thing->ns;
59 3 my $parser = XML::Elemental->parser;
60 3 my $doc = $parser->parse_string("<$name xmlns='$ns'>$str</$name>");
61 3 my $pseudo = $doc->contents->[0];
62 3 my $parent = $thing->elem;
63 3 $_->parent($parent) for @{$pseudo->contents};
64 3 $parent->contents($pseudo->contents);
65 3 $pseudo->contents([]);
66 3 1;
67 }
68  
69 22 1;
« Syndication/Text.pm ↑ Summary Syndication/Writer.pm »