blib/lib/XML/XSS/Role/Renderer.pm

filter: Statementstmt 88.0% 66 / 75 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.5% 97 / 119 CC 8 SCAR 4.7
CC
8
Cov
88%
style_attribute_hash
4.0
detach_from_stylesheet
2.1
set
2.0
CRAP 1.6
« blib/lib/XML/XSS/StyleAttribute.pm ↑ Summary
1 package XML::XSS::Role::Renderer;
2 BEGIN {
3 20 ▶ $XML::XSS::Role::Renderer::AUTHORITY = 'cpan:YANICK';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 {
6 20 $XML::XSS::Role::Renderer::VERSION = '0.3.4';
7 }
8 # ABSTRACT: XML::XSS role for rendering rule
9  
10 20 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 20 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 20 ▶use Scalar::Util qw/ refaddr /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 20 has stylesheet => (
16 isa => 'XML::XSS',
17 weak_ref => 1,
18 is => 'ro',
19 required => 1,
20 handles => [qw/ render stash /],
21 );
22  
23 20 has _within_apply => ( is => 'rw', );
24  
25 20 has is_detached => (
26 is => 'rw',
27 default => 0,
28 );
29  
30 20 requires 'apply';
31  
32 sub detach_from_stylesheet {
33 2 ▶ my $self = shift;
Subroutine detach_from_stylesheet: called CC=2 SCAR=7.2
Pod undocumented
34  
35 2 ▶ $self->stylesheet->detach($self) unless $self->is_detached;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_detached 2 0 2
36 }
37  
38 before apply => sub {
39 183 ▶ $_[0]->_set_within_apply(1);
Subroutine __ANON__: called CC=1 SCAR=0.0
40 20 };
41  
42 after apply => sub {
43 183 ▶ $_[0]->_set_within_apply(0);
Subroutine __ANON__: called CC=1 SCAR=0.0
44 20 };
45  
46 sub set {
47 62 ▶ my ( $self, %attrs ) = @_;
Subroutine set: called CC=2 SCAR=6.9
Pod undocumented
48  
49 62 ▶ while ( my ( $k, $v ) = each %attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attrs) 94 62 156
50 94 my $setter = "set_$k";
51 94 $self->$setter($v);
52 }
53 }
54  
55 sub _render {
56 862 ▶ my ( $self, $attr, $node, $args ) = @_;
Subroutine _render: called CC=1 SCAR=0.0
57  
58 862 return $self->$attr->render( $self, $node, $args );
59 }
60  
61  
62 # http://use.perl.org/~tokuhirom/journal/36582
63 20 ▶__PACKAGE__->meta->add_package_symbol( '&()' => sub { } ); # dummy
Subroutine (): not called CC=1 SCAR=0.0
64 0 ▶__PACKAGE__->meta->add_package_symbol( '&(""' => sub { shift->stringify } );
Subroutine __ANON__: not called CC=1 SCAR=2.6
Subroutine ("": not called CC=1 SCAR=2.6
65 2 ▶__PACKAGE__->meta->add_package_symbol( '&(%=' => sub { shift->_assign_attrs(shift) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
66 12 ▶__PACKAGE__->meta->add_package_symbol( '&(.' => sub { shift->_concat_overload(shift) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
67 179 ▶__PACKAGE__->meta->add_package_symbol( '&(bool' => sub { 1 } );
Subroutine (bool: called CC=1 SCAR=0.0
68 4 ▶__PACKAGE__->meta->add_package_symbol( '&(eq' => sub { shift->_equal_overload(shift) } );
Subroutine (eq: called CC=1 SCAR=0.0
69 0 ▶__PACKAGE__->meta->add_package_symbol( '&(==' => sub { shift->_equal_overload(shift) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
70 #__PACKAGE__->meta->add_package_symbol( '&(<<=' => sub { shift->_assign_content(shift) } );
71 2 ▶__PACKAGE__->meta->add_package_symbol( '&(=' => sub { shift } );
Subroutine __ANON__: called CC=1 SCAR=0.0
72  
73  
74 sub stringify {
75 0 ▶ my $self = shift;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod undocumented
76 0 return 'XML::XSS::Element::' . refaddr $self;
77 }
78  
79 sub _assign_content {
80 0 ▶ $_[0]->set_content( $_[1] );
Subroutine _assign_content: not called CC=1 SCAR=6.9
81 0 $_[0];
82 }
83  
84 sub _assign_content_xsst {
85 0 ▶ $_[0]->set_content( XML::XSS::xsst( $_[1] ) );
Subroutine _assign_content_xsst: not called CC=1 SCAR=6.9
86 0 $_[0];
87 }
88  
89 sub _assign_attrs {
90 2 ▶ my ( $self, $attrs ) = @_;
Subroutine _assign_attrs: called CC=2 SCAR=6.9
91 2 for ( keys %$attrs ) {
92 6 my $m = "set_$_";
93 6 $self->$m( $attrs->{$_} );
94 }
95 2 $self;
96 }
97  
98 sub _equal_overload {
99 4 ▶ my ( $a, $b ) = @_;
Subroutine _equal_overload: called CC=1 SCAR=0.0
100  
101 4 return refaddr($a) == refaddr($b);
102 }
103  
104 sub _concat_overload {
105 12 ▶ my ( $self, $attr ) = @_;
Subroutine _concat_overload: called CC=2 SCAR=6.9
106  
107 12 ▶ return $self if $attr eq 'style';
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "style" 1 11 12
108  
109 11 return $self->$attr;
110 }
111  
112  
113  
114 sub style_attributes {
115 9 ▶ my $self = shift;
Subroutine style_attributes: called CC=1 SCAR=0.0
Pod undocumented
116  
117 return
118 sort
119 51 map { $_->name }
120 51 grep { 'XML::XSS::Role::StyleAttribute' ~~ @{ $_->applied_traits } }
121 78 grep { $_->has_applied_traits }
122 9 map { $self->meta->get_attribute( $_ ) }
123 $self->meta->get_attribute_list
124 }
125  
126 sub style_attribute_hash {
127 8 ▶ my $self = shift;
Subroutine style_attribute_hash: called CC=4 SCAR=13.9
Pod undocumented
128 8 my %opt = @_;
129  
130 8 my %hash;
131  
132 8 for my $attr ( $self->style_attributes ) {
133 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
134 14 $hash{$attr} = $self->$attr->value;
135 }
136  
137 8 return %hash;
138
139 }
140  
141 20 1;
142  
143 __END__
144  
145 =pod
146  
147 =head1 NAME
148  
149 XML::XSS::Role::Renderer - XML::XSS role for rendering rule
150  
151 =head1 VERSION
152  
153 version 0.3.4
154  
155 =head1 OVERLOADING
156  
157 =head2 Concatenation (.)
158  
159 Shortcut to get the style attributes.
160  
161 my $pre = $xss.'chapter'.'pre';
162  
163 is equivalent to
164  
165 my $pre = $xss->get('chapter')->pre;
166  
167 In addition of the usual style attributes, the special keyword 'style' can
168 also be used, which returns the object itself. Which is useful to use the
169 other overloaded operators, which don't work without it. :-(
170  
171 # will work
172 $xss.'chapter'.'style' %= {
173 pre => '<div class="chapter">',
174 post => '</div>',
175 };
176  
177 # will work too
178 my $chapter = $xss.'chapter';
179 $chapter %= {
180 pre => '<div class="chapter">',
181 post => '</div>',
182 };
183  
184 # won't work!
185 $xss.'chapter' %= {
186 pre => '<div class="chapter">',
187 post => '</div>',
188 };
189  
190 =head2 %=
191  
192 Assigns a set of style attributes.
193  
194 $xss.'chapter'.'style' %= {
195 pre => '<div class="chapter">',
196 post => '</div>',
197 };
198  
199 is equivalent to
200  
201 $xss->set( chapter => {
202 pre => '<div class="chapter">',
203 post => '</div>',
204 } );
205  
206 =head1 AUTHOR
207  
208 Yanick Champoux <yanick@cpan.org>
209  
210 =head1 COPYRIGHT AND LICENSE
211  
212 This software is copyright (c) 2013 by Yanick Champoux.
213  
214 This is free software; you can redistribute it and/or modify it under
215 the same terms as the Perl 5 programming language system itself.
216  
217 =cut
« blib/lib/XML/XSS/StyleAttribute.pm ↑ Summary