blib/lib/XML/XSS/Text.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 6 / 6 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 91.6% 55 / 60 CC 8 SCAR 14.2
CC
8
Cov
96%
apply
7.0
clear
2.0
BEGIN
1.0
CRAP 4.2
« Build ↑ Summary blib/lib/XML/XSS/Role/StyleAttribute.pm »
1 package XML::XSS::Text;
2 BEGIN {
3 15 ▶ $XML::XSS::Text::AUTHORITY = 'cpan:YANICK';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 {
6 15 $XML::XSS::Text::VERSION = '0.3.4';
7 }
8 # ABSTRACT: XML::XSS text stylesheet rule
9  
10  
11  
12 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use MooseX::Clone;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 15 with 'XML::XSS::Role::Renderer', 'MooseX::Clone';
17  
18 15 ▶no warnings qw/ uninitialized /;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21  
22 15 has replace => (
23 traits => [ qw/ XML::XSS::Role::StyleAttribute Clone / ]
24 );
25  
26  
27 15 has filter => (
28 traits => [ qw/ XML::XSS::Role::StyleAttribute Clone / ]
29 );
30  
31  
32  
33 15 has [ qw/ pre post / ] => (
34 traits => [ qw/ XML::XSS::Role::StyleAttribute Clone/ ]
35 );
36  
37  
38 15 has process => (
39 traits => [ qw/ XML::XSS::Role::StyleAttribute Clone/ ]
40 );
41  
42 sub clear {
43 2 ▶ my $self = shift;
Subroutine clear: called CC=2 SCAR=6.9
Pod undocumented
44  
45 2 for ( qw/ pre post replace filter process / ) {
46 10 my $setter = "clear_$_";
47 10 $self->$setter;
48 }
49  
50 }
51  
52 sub apply {
53 34 ▶ my ( $self, $node, $args ) = @_;
Subroutine apply: called CC=7 SCAR=19.5
54 34 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
340
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
55  
56 return
57 34 ▶ if $self->has_process and !$self->_render( 'process', $node, $args );
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_process and not $self->_render("process", $node, $args) 1 33 34
Condition66%2/3
$self->has_process and not $self->_render("process", $node, $args)
!ll&&!rl&&r
3301
MC/DC50%1/2
$self->has_process and not $self->_render("process", $node, $args)
$self->has_process not $self->_render("process", $node, $args)
Truth table66%2/3
A and not(B)
A= $self->has_processB= not $self->_render("process", $node, $args)
ABresult
0X0
100
111
58  
59 33 my $text = $node->data;
60  
61 33 my $output;
62 33 $output .= $self->_render( 'pre', $node, $args );
63  
64 33 ▶ if ( $self->has_replace ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_replace) 2 31 33
65 2 $text = $self->_render( 'replace', $node, $args );
66 }
67  
68 33 ▶ if ( $self->has_filter ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_filter) 2 31 33
69 2 $text = $self->filter->value()->() for $text; # quick alias to $_
70 }
71  
72 33 $output .= $text;
73 33 $output .= $self->_render( 'post', $node, $args );
74  
75 33 return $output;
76 }
77  
78 15 1;
79  
80 __END__
81  
82 =pod
83  
84 =head1 NAME
85  
86 XML::XSS::Text - XML::XSS text stylesheet rule
87  
88 =head1 VERSION
89  
90 version 0.3.4
91  
92 =head1 SYNOPSIS
93  
94 use XML::XSS;
95  
96 my $xss = XML::XSS->new;
97  
98 my $txt_style = $xss->text;
99  
100 $txt_style->set_pre( "=pod\n" );
101 $txt_style->set_post( "=cut\n" );
102  
103 print $xss->render( '<doc>yadah yadah</doc>' );
104  
105 =head1 DESCRIPTION
106  
107 A C<XML::XSS> rule that matches against the text nodes of a
108 document to be rendered.
109  
110 =head1 RENDERING ATTRIBUTES
111  
112 For a document, the displayed attributes follow the template:
113  
114 pre
115 [text]
116 post
117  
118 =head2 pre
119  
120 Printed before the text.
121  
122 =head3 getter - pre()
123  
124 =head3 setter - set_pre( $pre )
125  
126 =head2 replace
127  
128 If defined, its value is used instead of the original text.
129  
130 =head2 filter
131  
132 Can only accept a sub reference. If defined, the text will be passed
133 to the function as C<$_> and the returned value will be printed out. Still is applied
134 even if C<replace> is used.
135  
136 $xss->set( '#text', {
137 filter => sub { uc },
138 } );
139  
140 =head2 post
141  
142 Printed after the text.
143  
144 =head3 getter - post()
145  
146 =head3 setter - set_post( $post )
147  
148 =head2 process
149  
150 If it resolves to false, skip the element altogether.
151  
152 =head3 get_process()
153  
154 Attribute getter.
155  
156 =head3 set_process( $process )
157  
158 Attribute setter.
159  
160 =head1 AUTHOR
161  
162 Yanick Champoux <yanick@cpan.org>
163  
164 =head1 COPYRIGHT AND LICENSE
165  
166 This software is copyright (c) 2013 by Yanick Champoux.
167  
168 This is free software; you can redistribute it and/or modify it under
169 the same terms as the Perl 5 programming language system itself.
170  
171 =cut
« Build ↑ Summary blib/lib/XML/XSS/Role/StyleAttribute.pm »