XSS/Role/Renderer.pm

filter: Statementstmt 88.3% 68 / 77 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 73.0% 19 / 26 Podpod 0.0% 0 / 5 totaltotal 81.8% 99 / 121 CC 8 SCAR 4.7
CC
8
Cov
89%
style_attribute_hash
4.0
detach_from_stylesheet
2.1
set
2.0
CRAP 1.6
« XSS/StyleAttribute.pm ↑ Summary
1 package XML::XSS::Role::Renderer;
2 20 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: XML::XSS role for rendering rule
4 20 $XML::XSS::Role::Renderer::VERSION = '0.3.5';
5 20 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶use experimental 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 20 ▶use Scalar::Util qw/ refaddr /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 20 has stylesheet => (
13 isa => 'XML::XSS',
14 weak_ref => 1,
15 is => 'ro',
16 required => 1,
17 handles => [qw/ render stash /],
18 );
19  
20 20 has _within_apply => ( is => 'rw', );
21  
22 20 has is_detached => (
23 is => 'rw',
24 default => 0,
25 );
26  
27 20 requires 'apply';
28  
29 2 ▶sub detach_from_stylesheet {
Subroutine detach_from_stylesheet: called CC=2 SCAR=7.2
Pod undocumented
30 2 my $self = shift;
31  
32 2 ▶ $self->stylesheet->detach($self) unless $self->is_detached;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_detached 2 0 2
33 }
34  
35 183 ▶before apply => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 183 $_[0]->_set_within_apply(1);
37 20 };
38  
39 183 ▶after apply => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
40 183 $_[0]->_set_within_apply(0);
41 20 };
42  
43 62 ▶sub set {
Subroutine set: called CC=2 SCAR=6.9
Pod undocumented
44 62 my ( $self, %attrs ) = @_;
45  
46 62 ▶ while ( my ( $k, $v ) = each %attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attrs) 94 62 156
47 94 my $setter = "set_$k";
48 94 $self->$setter($v);
49 }
50 }
51  
52 862 ▶sub _render {
Subroutine _render: called CC=1 SCAR=0.0
53 862 my ( $self, $attr, $node, $args ) = @_;
54  
55 862 return $self->$attr->render( $self, $node, $args );
56 }
57  
58  
59 # http://use.perl.org/~tokuhirom/journal/36582
60 20 ▶__PACKAGE__->meta->add_package_symbol( '&()' => sub { } ); # dummy
Subroutine (): not called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
61 0 ▶__PACKAGE__->meta->add_package_symbol( '&(""' => sub { shift->stringify } );
Subroutine ("": not called CC=1 SCAR=1.2
62 2 ▶__PACKAGE__->meta->add_package_symbol( '&(%=' => sub { shift->_assign_attrs(shift) } );
Subroutine (%=: called CC=1 SCAR=0.0
63 0 ▶__PACKAGE__->meta->add_package_symbol( '&(.' => sub { shift->_concat_overload(shift) } );
Subroutine __ANON__: called CC=1 SCAR=0.4
64 67 ▶__PACKAGE__->meta->add_package_symbol( '&(bool' => sub { 1 } );
Subroutine (bool: called CC=1 SCAR=0.0
65 4 ▶__PACKAGE__->meta->add_package_symbol( '&(eq' => sub { shift->_equal_overload(shift) } );
Subroutine (eq: called CC=1 SCAR=0.0
66 0 ▶__PACKAGE__->meta->add_package_symbol( '&(==' => sub { shift->_equal_overload(shift) } );
Subroutine (==: not called CC=1 SCAR=1.2
67 #__PACKAGE__->meta->add_package_symbol( '&(<<=' => sub { shift->_assign_content(shift) } );
68 2 ▶__PACKAGE__->meta->add_package_symbol( '&(=' => sub { shift } );
Subroutine (=: called CC=1 SCAR=0.0
69  
70  
71 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my $self = shift;
73 0 return 'XML::XSS::Element::' . refaddr $self;
74 }
75  
76 0 ▶sub _assign_content {
Subroutine _assign_content: not called CC=1 SCAR=6.9
77 0 $_[0]->set_content( $_[1] );
78 0 $_[0];
79 }
80  
81 0 ▶sub _assign_content_xsst {
Subroutine _assign_content_xsst: not called CC=1 SCAR=6.9
82 0 $_[0]->set_content( XML::XSS::xsst( $_[1] ) );
83 0 $_[0];
84 }
85  
86 2 ▶sub _assign_attrs {
Subroutine _assign_attrs: called CC=2 SCAR=6.9
87 2 my ( $self, $attrs ) = @_;
88 2 for ( keys %$attrs ) {
89 6 my $m = "set_$_";
90 6 $self->$m( $attrs->{$_} );
91 }
92 2 $self;
93 }
94  
95 4 ▶sub _equal_overload {
Subroutine _equal_overload: called CC=1 SCAR=0.0
96 4 my ( $a, $b ) = @_;
97  
98 4 return refaddr($a) == refaddr($b);
99 }
100  
101 12 ▶sub _concat_overload {
Subroutine _concat_overload: called CC=2 SCAR=6.9
102 12 my ( $self, $attr ) = @_;
103  
104 12 ▶ return $self if $attr eq 'style';
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "style" 1 11 12
105  
106 11 return $self->$attr;
107 }
108  
109  
110  
111 9 ▶sub style_attributes {
Subroutine style_attributes: called CC=1 SCAR=0.0
Pod undocumented
112 9 my $self = shift;
113  
114 return
115 sort
116 51 map { $_->name }
117 51 grep { 'XML::XSS::Role::StyleAttribute' ~~ @{ $_->applied_traits } }
118 78 grep { $_->has_applied_traits }
119 9 map { $self->meta->get_attribute( $_ ) }
120 $self->meta->get_attribute_list
121 }
122  
123 8 ▶sub style_attribute_hash {
Subroutine style_attribute_hash: called CC=4 SCAR=13.9
Pod undocumented
124 8 my $self = shift;
125 8 my %opt = @_;
126  
127 8 my %hash;
128  
129 8 for my $attr ( $self->style_attributes ) {
130 44 ▶ next unless $opt{all} or $self->$attr->has_value;
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"all"} or $self->$attr->has_value 30 14 44
Condition100%3/3
$opt{"all"} or $self->$attr->has_value
l!l&&r!l&&!r
7730
MC/DC100%2/2
$opt{"all"} or $self->$attr->has_value
$opt{"all"} $self->$attr->has_value
Truth table100%3/3
A or B
A= $opt{"all"}B= $self->$attr->has_value
ABresult
1X1
011
000
131 14 $hash{$attr} = $self->$attr->value;
132 }
133  
134 8 return %hash;
135
136 }
137  
138 20 1;
139  
140 __END__
« XSS/StyleAttribute.pm ↑ Summary