| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | if $IN_SCOPE; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | my $opts = shift(@args) if ref($args[0]) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | ▶ | if (defined) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | s/&/&/g; s/"/"/g; s/</</g; s/>/>/g; s/'/'/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
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | ▶ | my $level = ($opts->{into_level} || 1) + $extra_levels; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'into_level'} || 1
MC/DC100%1/1
$opts->{'into_level'} || 1
$opts->{'into_level'}
Truth table100%2/2
A
A= $opts->{'into_level'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 24 | ▶ | : (map +(ref $_ ? $$_ : XML::Tags::to_xml_string($_) ), @{$_[0]}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
ref $other and $other =~ /[a-z]=[A-Z]/ and $other->isa(__PACKAGE__)
ref $other and $other =~ /[a-z]=[A-Z]/
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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | bless(\@new, ref($self)); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||