blib/lib/HTML/Strip.pm

filter: Statementstmt 59.5% 56 / 94 Branchbran 42.3% 11 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 59.0% 13 / 22 Podpod 100% 14 / 14 totaltotal 60.2% 94 / 156 CC 13 SCAR 9.8
CC
13
Cov
56%
new
4.7
new
4.7
_do_filter
4.1
CRAP 2.7
↑ Summary strip_html.c »
1 package HTML::Strip;
2  
3 13 require DynaLoader;
4 13 our @ISA = qw(DynaLoader);
5 13 our $VERSION = '2.12';
6 13 bootstrap HTML::Strip $VERSION;
7  
8 13 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 13 my $_html_entities_p = eval { require HTML::Entities; 1 };
15  
16 13 ▶my %defaults = (
Branch: 1 branch
BranchTrueFalseTotal
$_html_entities_p ? : 13 0 13
17 striptags => [qw( title
18 style
19 script
20 applet )],
21 emit_spaces => 1,
22 emit_newlines => 0,
23 decode_entities => 1,
24 filter => $_html_entities_p ? 'filter_entities' : undef,
25 auto_reset => 0,
26 debug => 0,
27 );
28  
29 17 ▶sub new {
Subroutine new: called CC=3 SCAR=15.4
Pod documented
30 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=15.4
Pod documented
31 0 my $obj = _create();
32 0 bless $obj, $class;
33  
34 0 my %args = (%defaults, @_);
35 0 ▶ while( my ($key, $value) = each %args ) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = each %args) 119 17 136
if (() = each %args) 0 0 0
36 0 my $method = "set_${key}";
37 0 ▶ if( $obj->can($method) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->can($method)) { } 119 0 119
if ($obj->can($method)) { } 0 0 0
38 0 $obj->$method($value);
39 } else {
40 0 Carp::carp "Invalid setting '$key'";
41 }
42 }
43 0 return $obj;
44 }
45  
46 19 ▶sub set_striptags {
Subroutine set_striptags: called CC=2 SCAR=9.2
Pod documented
47 0 ▶ my ($self, @tags) = @_;
Subroutine set_striptags: not called CC=2 SCAR=9.2
Pod documented
48 0 ▶ if( ref($tags[0]) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $tags[0] eq 'ARRAY') { } 18 1 19
if (ref $tags[0] eq 'ARRAY') { } 0 0 0
49 0 $self->_set_striptags_ref( $tags[0] );
50 } else {
51 0 $self->_set_striptags_ref( \@tags );
52 }
53 }
54  
55 {
56 # an inside-out object approach
57 # for the 'filter' attribute
58 13 my %filter_of;
59  
60 17 ▶ sub set_filter {
Subroutine set_filter: called CC=1 SCAR=1.2
Pod documented
61 0 ▶ my ($self, $filter) = @_;
Subroutine set_filter: not called CC=1 SCAR=1.2
Pod documented
62 0 $filter_of{0+$self} = $filter;
63 }
64  
65 40 ▶ sub filter {
Subroutine filter: called CC=1 SCAR=1.2
Pod documented
66 0 ▶ my $self = shift;
Subroutine filter: not called CC=1 SCAR=1.2
Pod documented
67 0 return $filter_of{0+$self}
68 }
69  
70 # XXX rename _xs_destroy() to DESTROY() in Strip.xs if removing this code
71 17 ▶ sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=1.2
72 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=1 SCAR=1.2
73 0 delete $filter_of{0+$self};
74 0 $self->_xs_destroy;
75 }
76 }
77  
78 # $decoded_string = $self->filter_entities( $string )
79 13 ▶sub filter_entities {
Subroutine filter_entities: called CC=2 SCAR=10.8
Pod documented
80 0 ▶ my $self = shift;
Subroutine filter_entities: not called CC=2 SCAR=11.6
Pod documented
81 0 ▶ if( $self->decode_entities ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->decode_entities) 38 0 38
if ($self->decode_entities) 0 0 0
82 0 return HTML::Entities::decode($_[0]);
83 }
84 0 return $_[0];
85 }
86  
87 40 ▶sub _do_filter {
Subroutine _do_filter: called CC=3 SCAR=14.2
88 0 ▶ my $self = shift;
Subroutine _do_filter: not called CC=3 SCAR=14.2
89 0 my $filter = $self->filter;
90 # no filter: return immediately
91 0 ▶ return $_[0] unless defined $filter;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $filter 1 39 40
unless defined $filter 0 0 0
92  
93 0 ▶ if ( !ref $filter ) { # method name
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $filter) { } 38 1 39
if (not ref $filter) { } 0 0 0
94 0 return $self->$filter( @_ );
95 } else { # code ref
96 0 return $filter->( @_ );
97 }
98 }
99  
100 40 ▶sub parse {
Subroutine parse: called CC=1 SCAR=1.2
Pod documented
101 0 ▶ my ($self, $text) = @_;
Subroutine parse: not called CC=1 SCAR=1.2
Pod documented
102 0 my $stripped = $self->_strip_html( $text );
103 0 return $self->_do_filter( $stripped );
104 }
105  
106 24 ▶sub eof {
Subroutine eof: called CC=1 SCAR=1.2
Pod documented
107 0 ▶ my $self = shift;
Subroutine eof: not called CC=1 SCAR=1.2
Pod documented
108 0 $self->_reset();
109 }
110  
111 13 1;
112 __END__
↑ Summary strip_html.c »