| 1 | package XML::XSS::StyleAttribute; | ||||||||||||||||||||
| 2 | BEGIN { | ||||||||||||||||||||
| 3 | 21 | ▶ | $XML::XSS::StyleAttribute::AUTHORITY = 'cpan:YANICK'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | { | ||||||||||||||||||||
| 6 | 21 | $XML::XSS::StyleAttribute::VERSION = '0.3.4'; | |||||||||||||||||||
| 7 | } | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # ABSTRACT: Style attribute for XML::XSS stylesheet rule | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 21 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 21 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 21 | ▶ | use MooseX::Clone; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 21 | with 'MooseX::Clone'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 21 | ▶ | use Scalar::Util qw/ refaddr /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 21 | ▶ | no warnings qw/ uninitialized /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | use overload | ||||||||||||||||||||
| 24 | 56 | ▶ | 'bool' => sub { $_[0]->value }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 0 | ▶ | '""' => sub { $_[0]->value }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 26 | 2 | ▶ | '+' => sub { $_[0]->value + $_[1] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 0 | ▶ | '0+' => sub { $_[0]->value }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 28 | 7 | ▶ | '*=' => sub { $_[0]->set_value( $_[1] ) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 2 | ▶ | 'x=' => sub { $_[0]->set_value( XML::XSS::xsst( $_[1] ) ) }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 9 | ▶ | '=' => sub { shift }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 'eq' => sub { | ||||||||||||||||||||
| 32 | 0 | ▶ | my ( $a, $b ) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 33 | 0 | ▶ | return( ref($a) eq ref($b) and refaddr($a) == refaddr($b) ); | ||||||||||||||||||
|
Condition0%0/3
ref $a eq ref $b && builtin::refaddr($a) == builtin::refaddr($b)
MC/DC0%0/2
ref $a eq ref $b && builtin::refaddr($a) == builtin::refaddr($b)
ref $a eq ref $b
builtin::refaddr($a) == builtin::refaddr($b)
Truth table0%0/3
A && B
A= ref $a eq ref $bB= builtin::refaddr($a) == builtin::refaddr($b)
| |||||||||||||||||||||
| 34 | 21 | ▶ | }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 21 | has 'value' => ( | |||||||||||||||||||
| 38 | is => 'rw', | ||||||||||||||||||||
| 39 | clearer => 'clear_value', | ||||||||||||||||||||
| 40 | predicate => 'has_value', | ||||||||||||||||||||
| 41 | traits => [qw/ Clone /], | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | after 'set_value' => sub { | ||||||||||||||||||||
| 45 | 115 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 115 | ▶ | $self->clear_value unless defined $self->value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 21 | }; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | #sub clone { | ||||||||||||||||||||
| 51 | # return XML::XSS::StyleAttribute->new( | ||||||||||||||||||||
| 52 | # value => $_[0]->value | ||||||||||||||||||||
| 53 | # ); | ||||||||||||||||||||
| 54 | #} | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | sub render { | ||||||||||||||||||||
| 57 | 862 | ▶ | my ( $self, $r, $node, $args ) = @_; | ||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 862 | ▶ | return unless $self->has_value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 92 | my $value = $self->value; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 92 | ▶ | return ref $value ? $value->( $r, $node, $args ) : $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 21 | 1; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =pod | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =head1 NAME | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | XML::XSS::StyleAttribute - Style attribute for XML::XSS stylesheet rule | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =head1 VERSION | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | version 0.3.4 | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | use XML::XSS; | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | my $xss = XML::XSS->new; | ||||||||||||||||||||
| 85 | my $attribute = $xss->get('chapter')->pre; | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | $attribute->set_value( '<div class="chapter">' ); | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =head1 DESCRIPTION | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | The C<XML::XSS::StyleAttribute> objects are the building blocks | ||||||||||||||||||||
| 92 | of the document transformation. They can be assigned a string, | ||||||||||||||||||||
| 93 | which is inserted verbatim in the rendered document | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | $xss->get('chapter')->set_pre( '<div class="chapter">' ); | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | or a sub reference, which return value is inserted in the rendered document | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | $xss->get('clock')->set_pre( sub { return "date and time are: " . localtime } ); | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | Upon execution, the sub references will be passed three parameters: the invoking rule, | ||||||||||||||||||||
| 102 | the L<XML::LibXML::Node> object currently rendered and the arguments ref given | ||||||||||||||||||||
| 103 | to C<render()>. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | $xss->set( 'div' => { | ||||||||||||||||||||
| 106 | intro => sub { | ||||||||||||||||||||
| 107 | my ( $self, $node, $args ) = @_; | ||||||||||||||||||||
| 108 | my @para = $node->findnodes( '@para' ); | ||||||||||||||||||||
| 109 | return "<p>node has " . @para . " para child nodes.</p>"; | ||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | } ); | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =head1 OVERLOADING | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head2 *= | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Assigns the right value to the attribue. | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | $xss.'chapter'.'pre' *= "<div class='chapter'>"; | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | is equivalent to | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | $xss->set( chapter => { pre => "<div class='chapter'>" } ); | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head2 x= | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | Similar to '*=', but considers the right side as a template and converts it | ||||||||||||||||||||
| 128 | via C<xsst>. | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | $xss.'chapter'.'pre' x= q{ | ||||||||||||||||||||
| 131 | <div class="chapter"> | ||||||||||||||||||||
| 132 | <% $r->stylesheet->stash{chapter_nbr}++ %> | ||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | is equivalent to | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | $xss->set( 'chapter' => { pre => xsst( <<'END_TEMPLATE' ) } ); | ||||||||||||||||||||
| 138 | <div class="chapter"> | ||||||||||||||||||||
| 139 | <% $r->stylesheet->stash{chapter_nbr}++ %> | ||||||||||||||||||||
| 140 | END_TEMPLATE | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head2 value | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | The string or sub reference used by the style attribute. | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | # long way | ||||||||||||||||||||
| 149 | $xss->get('chapter')->pre->set_value( '<div class="chapter">' ); | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | # short way | ||||||||||||||||||||
| 152 | $xss->set( chapter => { pre => '<div class="chapter">' } ); | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | # shortest way | ||||||||||||||||||||
| 155 | $xss.'chapter'.'pre' *= '<div class="chapter">'; | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =head1 AUTHOR | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | Yanick Champoux <yanick@cpan.org> | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | This software is copyright (c) 2013 by Yanick Champoux. | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 166 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||