blib/lib/XML/Tags.pm

filter: Statementstmt 95.9% 94 / 98 Branchbran 69.2% 18 / 26 Conditioncond 62.5% 5 / 8 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 24 / 24 Podpod 0.0% 0 / 1 totaltotal 88.2% 142 / 161 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 11 ▶sub import {
Subroutine import: called CC=4 SCAR=14.1
13 11 ▶ die "Can't import XML::Tags into a scope when already compiling one that uses it"
Branch: 1 branch
BranchTrueFalseTotal
if $IN_SCOPE 0 11 11
14 if $IN_SCOPE;
15 11 my ($class, @args) = @_;
16 11 ▶ my $opts = shift(@args) if ref($args[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[0] eq "HASH" 6 5 11
17 11 my $target = $class->_find_target(0, $opts);
18 11 my @tags = $class->_find_tags(@args);
19 11 my $unex = $class->_export_tags_into($target => @tags);
20 11 ▶ if ($INC{"bareword/filehandles.pm"}) { bareword::filehandles->import }
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"bareword/filehandles.pm"}) 0 11 11
21 11 $class->_install_unexporter($unex);
22 11 $IN_SCOPE = 1;
23 }
24  
25 25 ▶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 25 ref($_)
28 ? (ref $_ eq 'SCALAR' ? $$_ : $_)
29 48 ▶ : do { local $_ = $_; # copy
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 43 5 48
ref $_ eq 'SCALAR' ? : 42 1 43
30 5 ▶ if (defined) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 5 0 5
31 5 s/&/&amp;/g; s/"/&quot;/g; s/</&lt;/g; s/>/&gt;/g; $_;
32 } else {
33 0 ''
34 }
35 }
36 } @_
37 }
38  
39 11 ▶sub _find_tags { shift; @_ }
Subroutine _find_tags: called CC=1 SCAR=0.0
40  
41 11 ▶sub _find_target {
Subroutine _find_target: called CC=3 SCAR=11.0
42 11 my ($class, $extra_levels, $opts) = @_;
43 11 ▶ return $opts->{into} if defined($opts->{into});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"into"} 0 11 11
44 11 ▶ my $level = ($opts->{into_level} || 1) + $extra_levels;
Condition100%2/2
$opts->{'into_level'} || 1
l!l
65
MC/DC100%1/1
$opts->{'into_level'} || 1
$opts->{'into_level'}
Truth table100%2/2
A
A= $opts->{'into_level'}
Aresult
11
00
45 11 return (caller($level))[0];
46 }
47  
48 22 ▶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 22 delete ${CORE::GLOBAL::}{glob};
56 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 22 *{'CORE::GLOBAL::glob'} = $_[0];
58 }
59  
60 11 ▶sub _export_tags_into {
Subroutine _export_tags_into: called CC=2 SCAR=6.9
61 11 my ($class, $into, @tags) = @_;
62 11 foreach my $tag (@tags) {
63 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 624 tie *{"${into}::${tag}"}, 'XML::Tags::TIEHANDLE', \"<${tag}>";
65 }
66 15 ▶ _set_glob(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
67 15 local $XML::Tags::StringThing::IN_GLOBBERY = 1;
68 15 \('<'."$_[0]".'>');
69 11 });
70 11 ▶ overload::constant(q => sub { XML::Tags::StringThing->from_constant(@_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
71 11 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
72 11 foreach my $tag (@tags) {
73 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 624 delete ${"${into}::"}{$tag}
75 }
76 11 _set_glob(\&File::Glob::csh_glob);
77 11 overload::remove_constant('q');
78 11 $IN_SCOPE = 0;
79 11 };
80 }
81  
82 11 ▶sub _install_unexporter {
Subroutine _install_unexporter: called CC=1 SCAR=0.0
83 11 my ($class, $unex) = @_;
84 11 $^H |= 0x20000; # localize %^H
85 11 $^H{'XML::Tags::Unex'} = bless($unex, 'XML::Tags::Unex');
86 }
87  
88 package XML::Tags::TIEHANDLE;
89  
90 624 ▶sub TIEHANDLE { my $str = $_[1]; bless \$str, $_[0] }
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
91 10 ▶sub READLINE { ${$_[0]} }
Subroutine READLINE: called CC=1 SCAR=0.0
92  
93 package XML::Tags::Unex;
94  
95 11 ▶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: $@" 11 0 11
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 17 ▶sub stringify {
Subroutine stringify: called CC=3 SCAR=11.1
106 join(
107 '',
108 ((our $IN_GLOBBERY)
109 16 ▶ ? XML::Tags::to_xml_string(@{$_[0]})
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 0 1
110 17 ▶ : (map +(ref $_ ? $$_ : $_), @{$_[0]})
Branch: 1 branch
BranchTrueFalseTotal
our $IN_GLOBBERY ? : 16 1 17
111 )
112 );
113 }
114  
115 43 ▶sub from_constant {
Subroutine from_constant: called CC=2 SCAR=6.9
116 43 my ($class, $initial, $parsed, $type) = @_;
117 43 ▶ return $parsed unless $type eq 'qq';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "qq" 10 33 43
118 33 return $class->new($parsed);
119 }
120  
121 33 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
122 33 my ($class, $string) = @_;
123 33 bless([ \$string ], $class);
124 }
125  
126 2 ▶sub concat {
Subroutine concat: called CC=5 SCAR=18.0
127 2 my ($self, $other, $rev) = @_;
128 2 my @extra = do {
129 2 ▶ 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 2 2
Condition50%3/6
ref $other and $other =~ /[a-z]=[A-Z]/ and $other->isa(__PACKAGE__)
!ll&&!rl&&r
200
ref $other and $other =~ /[a-z]=[A-Z]/
!ll&&!rl&&r
110
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 2 $other;
133 }
134 };
135 2 my @new = @{$self};
136 2 ▶ $rev ? unshift(@new, @extra) : push(@new, @extra);
Branch: 1 branch
BranchTrueFalseTotal
$rev ? : 0 2 2
137 2 bless(\@new, ref($self));
138 }
139  
140 2 1;
« examples/bloggery/bloggery.cgi ↑ Summary blib/lib/HTML/Tags.pm »