blib/lib/XML/Tags.pm

filter: Statementstmt 95.9% 95 / 99 Branchbran 73.0% 19 / 26 Conditioncond 62.5% 5 / 8 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 24 / 24 Podpod 0.0% 0 / 1 totaltotal 88.8% 144 / 162 CC 19 SCAR 9.8
CC
19
Cov
89%
concat
6.1
import
4.1
to_xml_string
4.0
CRAP 2.7
« examples/bloggery/bloggery.cgi ↑ Summary blib/lib/HTML/Tags.pm »
1 package XML::Tags;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use File::Glob ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 require overload;
9  
10 2 my $IN_SCOPE = 0;
11  
12 13 ▶sub import {
Subroutine import: called CC=4 SCAR=14.1
13 13 ▶ die "Can't import XML::Tags into a scope when already compiling one that uses it"
Branch: 1 branch
BranchTrueFalseTotal
if $IN_SCOPE 0 13 13
14 if $IN_SCOPE;
15 13 my ($class, @args) = @_;
16 13 ▶ my $opts = shift(@args) if ref($args[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[0] eq "HASH" 7 6 13
17 13 my $target = $class->_find_target(0, $opts);
18 13 my @tags = $class->_find_tags(@args);
19 13 my $unex = $class->_export_tags_into($target => @tags);
20 0 ▶ if ($INC{"bareword/filehandles.pm"}) { bareword::filehandles->import }
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"bareword/filehandles.pm"}) 0 13 13
21 13 $class->_install_unexporter($unex);
22 13 $IN_SCOPE = 1;
23 }
24  
25 33 ▶sub to_xml_string {
Subroutine to_xml_string: called CC=4 SCAR=13.9
Pod undocumented
26 map { # string == text -> HTML, scalarref == raw HTML, other == passthrough
27 33 ref($_)
28 ? (ref $_ eq 'SCALAR' ? $$_ : $_)
29 64 ▶ : do { local $_ = $_; # copy
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 56 8 64
ref $_ eq 'SCALAR' ? : 53 3 56
30 8 ▶ if (defined) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 8 0 8
31 8 s/&/&amp;/g; s/"/&quot;/g; s/</&lt;/g; s/>/&gt;/g; s/'/&#39;/g; $_;
32 } else {
33 0 ''
34 }
35 }
36 } @_
37 }
38  
39 13 ▶sub _find_tags { shift; @_ }
Subroutine _find_tags: called CC=1 SCAR=0.0
40  
41 13 ▶sub _find_target {
Subroutine _find_target: called CC=3 SCAR=11.0
42 13 my ($class, $extra_levels, $opts) = @_;
43 13 ▶ return $opts->{into} if defined($opts->{into});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"into"} 0 13 13
44 13 ▶ my $level = ($opts->{into_level} || 1) + $extra_levels;
Condition100%2/2
$opts->{'into_level'} || 1
l!l
76
MC/DC100%1/1
$opts->{'into_level'} || 1
$opts->{'into_level'}
Truth table100%2/2
A
A= $opts->{'into_level'}
Aresult
11
00
45 13 return (caller($level))[0];
46 }
47  
48 26 ▶sub _set_glob {
Subroutine _set_glob: called CC=1 SCAR=0.0
49 # stupid insanity. delete anything already there so we disassociated
50 # the *CORE::GLOBAL::glob typeglob. Then the string reference call
51 # revivifies it - i.e. creates us a new glob, which we get a reference
52 # to, which we can then assign to.
53 # doing it without the quotes doesn't - it binds to the version in scope
54 # at compile time, which means after a delete you get a nice warm segv.
55 26 delete ${CORE::GLOBAL::}{glob};
56 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 26 *{'CORE::GLOBAL::glob'} = $_[0];
58 }
59  
60 13 ▶sub _export_tags_into {
Subroutine _export_tags_into: called CC=2 SCAR=6.9
61 13 my ($class, $into, @tags) = @_;
62 13 foreach my $tag (@tags) {
63 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 728 tie *{"${into}::${tag}"}, 'XML::Tags::TIEHANDLE', \"<${tag}>";
65 }
66 19 ▶ _set_glob(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
67 19 local $XML::Tags::StringThing::IN_GLOBBERY = 1;
68 19 \('<'."$_[0]".'>');
69 13 });
70 13 ▶ overload::constant(q => sub { XML::Tags::StringThing->from_constant(@_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
71 13 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
72 13 foreach my $tag (@tags) {
73 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 728 delete ${"${into}::"}{$tag}
75 }
76 13 _set_glob(\&File::Glob::csh_glob);
77 13 overload::remove_constant('q');
78 13 $IN_SCOPE = 0;
79 13 };
80 }
81  
82 13 ▶sub _install_unexporter {
Subroutine _install_unexporter: called CC=1 SCAR=0.0
83 13 my ($class, $unex) = @_;
84 13 $^H |= 0x20000; # localize %^H
85 13 $^H{'XML::Tags::Unex'} = bless($unex, 'XML::Tags::Unex');
86 }
87  
88 package XML::Tags::TIEHANDLE;
89  
90 728 ▶sub TIEHANDLE { my $str = $_[1]; bless \$str, $_[0] }
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
91 12 ▶sub READLINE { ${$_[0]} }
Subroutine READLINE: called CC=1 SCAR=0.0
92  
93 package XML::Tags::Unex;
94  
95 13 ▶sub DESTROY { local $@; eval { $_[0]->(); 1 } || warn "ARGH: $@" }
Subroutine DESTROY: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $_[0]->(); 1 } } or warn "ARGH: $@" 13 0 13
96  
97 package XML::Tags::StringThing;
98  
99 2 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
100 2 '.' => 'concat',
101 '""' => 'stringify',
102 fallback => 1
103 2 );
104  
105 24 ▶sub stringify {
Subroutine stringify: called CC=3 SCAR=11.0
106 join(
107 '',
108 ((our $IN_GLOBBERY)
109 21 ▶ ? XML::Tags::to_xml_string(@{$_[0]})
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 3 1 4
110 24 ▶ : (map +(ref $_ ? $$_ : XML::Tags::to_xml_string($_) ), @{$_[0]})
Branch: 1 branch
BranchTrueFalseTotal
our $IN_GLOBBERY ? : 21 3 24
111 )
112 );
113 }
114  
115 55 ▶sub from_constant {
Subroutine from_constant: called CC=2 SCAR=6.9
116 55 my ($class, $initial, $parsed, $type) = @_;
117 55 ▶ return $parsed unless $type eq 'qq';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "qq" 16 39 55
118 39 return $class->new($parsed);
119 }
120  
121 39 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
122 39 my ($class, $string) = @_;
123 39 bless([ \$string ], $class);
124 }
125  
126 5 ▶sub concat {
Subroutine concat: called CC=5 SCAR=18.0
127 5 my ($self, $other, $rev) = @_;
128 5 my @extra = do {
129 5 ▶ if (ref($other) && ($other =~ /[a-z]=[A-Z]/) && $other->isa(__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $other and $other =~ /[a-z]=[A-Z]/ and $other->isa(__PACKAGE__)) { } 0 5 5
Condition50%3/6
ref $other and $other =~ /[a-z]=[A-Z]/ and $other->isa(__PACKAGE__)
!ll&&!rl&&r
500
ref $other and $other =~ /[a-z]=[A-Z]/
!ll&&!rl&&r
320
MC/DC0%0/3
ref $other and $other =~ /[a-z]=[A-Z]/ and $other->isa(__PACKAGE__)
ref $other $other =~ /[a-z]=[A-Z]/ $other->isa(__PACKAGE__)
Truth table50%2/4
A and B and C
A= ref $otherB= $other =~ /[a-z]=[A-Z]/C= $other->isa(__PACKAGE__)
ABCresult
0XX0
10X0
1100
1111
130 0 @{$other}
131 } else {
132 5 $other;
133 }
134 };
135 5 my @new = @{$self};
136 5 ▶ $rev ? unshift(@new, @extra) : push(@new, @extra);
Branch: 1 branch
BranchTrueFalseTotal
$rev ? : 0 5 5
137 5 bless(\@new, ref($self));
138 }
139  
140 2 1;
« examples/bloggery/bloggery.cgi ↑ Summary blib/lib/HTML/Tags.pm »