| 1 | package XML::XSS::Stylesheet::HTML2TD; | ||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | 1 | $XML::XSS::Stylesheet::HTML2TD::VERSION = '0.3.5'; | |||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use XML::XSS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Perl::Tidy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | extends 'XML::XSS'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | style '*' => ( | |||||||||
| 11 | pre => \&pre_element, | ||||||||||
| 12 | post => '};', | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | style '#text' => ( | ||||||||||
| 16 | 0 | ▶ | process => sub { $_[1]->data =~ /\S/ }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | pre => "outs '", | ||||||||||
| 18 | post => "';", | ||||||||||
| 19 | 0 | ▶ | filter => sub { s/'/\\'/g; s/^\s+|\s+$//gm; $_ }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 20 | 1 | ); | |||||||||
| 21 | |||||||||||
| 22 | style '#document' => ( | ||||||||||
| 23 | 0 | ▶ | content => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 24 | 0 | my ( $self, $node, $args ) = @_; | |||||||||
| 25 | 0 | my $raw = $self->stylesheet->render( $node->childNodes ); | |||||||||
| 26 | |||||||||||
| 27 | 0 | my $output; | |||||||||
| 28 | my $err; | ||||||||||
| 29 | 0 | eval { | |||||||||
| 30 | 0 | Perl::Tidy::perltidy( | |||||||||
| 31 | source => \$raw, | ||||||||||
| 32 | destination => \$output, | ||||||||||
| 33 | errorfile => \$err, | ||||||||||
| 34 | ) | ||||||||||
| 35 | }; | ||||||||||
| 36 | |||||||||||
| 37 | # send the raw output if Tidy failed | ||||||||||
| 38 | 0 | ▶ | return $err ? $raw : $output; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | }, | ||||||||||
| 40 | 1 | ); | |||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub pre_element { | ||||||||
|
Subroutine
pre_element: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 43 | 0 | my ( $self, $node ) = @_; | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $name = $node->nodeName; | |||||||||
| 46 | |||||||||||
| 47 | 0 | return "$name {" . pre_attrs( $node ); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | sub pre_attrs { | ||||||||
|
Subroutine
pre_attrs: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 51 | 0 | my $node = shift; | |||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | my @attr = $node->attributes or return ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | 0 | my $output = 'attr { '; | |||||||||
| 56 | |||||||||||
| 57 | 0 | for ( @attr ) { | |||||||||
| 58 | 0 | my $value = $_->value; | |||||||||
| 59 | 0 | $value =~ s/'/'/g; | |||||||||
| 60 | 0 | $output .= $_->nodeName . ' => ' . "'$value'" . ', '; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | $output .= '};'; | |||||||||
| 64 | |||||||||||
| 65 | 0 | return $output; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1 | 1; | |||||||||
| 69 | |||||||||||
| 70 | __END__ | ||||||||||