blib/lib/Text/Trac/BlockNode.pm

filter: Statementstmt 100% 70 / 70 Branchbran 100% 12 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 13 / 13 Podpod 20.0% 1 / 5 totaltotal 94.5% 104 / 110 SCAR 25.6
CC
13
Cov
99%
_get_matched_parsers
8.0
parse
4.0
_get_parsers
2.0
CRAP 13.0
« blib/lib/Text/Trac/Ol.pm ↑ Summary blib/lib/Text/Trac/Ul.pm »
1 package Text::Trac::BlockNode;
2  
3 53 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 53 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 53 ▶use base qw( Class::Accessor::Fast Class::Data::Inheritable );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 53 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 53 ▶use Text::Trac::InlineNode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 53 our $VERSION = '0.23';
11  
12 53 __PACKAGE__->mk_classdata( block_nodes => [qw( heading hr p ul ol blockquote pre table dl )] );
13  
14 #__PACKAGE__->mk_classdata(
15 # inline_nodes => [ qw( bold_italic bold italic underline monospace strike sup sub br
16 # auto_link_http macro trac_links ) ]
17 #);
18 53 __PACKAGE__->mk_classdata( block_parsers => [] );
19  
20 53 __PACKAGE__->mk_classdata( inline_parsers => [] );
21  
22 53 __PACKAGE__->mk_accessors(qw( context pattern inline_parser ));
23  
24 sub new {
25 5462 ▶ my ( $class, $params ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
26 5462 my $self = { %$params, };
27 5462 bless $self, $class;
28 5462 $self->init;
29 5462 $self->inline_parser( Text::Trac::InlineNode->new( $self->context ) );
30 5462 return $self;
31 }
32  
33 sub init {
34 2666 ▶ my $self = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
35 2666 return $self;
36 }
37  
38 sub parse {
39 160 ▶ my $self = shift;
Subroutine parse: called CC=4 SCAR=13.9
Pod undocumented
40 160 my $c = $self->context;
41  
42 160 $self->block_parsers( $self->_get_parsers('block') );
43  
44 #$self->inline_parsers( $self->_get_parsers('inline') );
45  
46 160 ▶ while ( defined( my $l = $c->shiftline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = $c->shiftline)) 2314 160 2474
47 2314 ▶ next if $l =~ /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /^$/ 814 1500 2314
48 1500 for my $parser ( @{ $self->_get_matched_parsers( 'block', $l ) } ) {
49 1503 $parser->parse($l);
50 }
51 }
52 }
53  
54 sub escape {
55 177 ▶ my ( $self, $l ) = @_;
Subroutine escape: called CC=1 SCAR=0.0
Pod undocumented
56 177 return $self->inline_parser->escape($l);
57 }
58  
59 sub replace {
60 2894 ▶ my ( $self, $l ) = @_;
Subroutine replace: called CC=1 SCAR=0.0
Pod undocumented
61 2894 return $self->inline_parser->parse($l);
62 }
63  
64 sub _get_parsers {
65 918 ▶ my ( $self, $type ) = @_;
Subroutine _get_parsers: called CC=2 SCAR=6.9
66  
67 918 $type .= '_nodes';
68 918 my @parsers;
69 918 for ( @{ $self->$type } ) {
70 2956 my $class = 'Text::Trac::' . $self->_camelize($_);
71 2956 $class->require;
72 2956 push @parsers, $class->new( { context => $self->context } );
73 }
74 918 return \@parsers;
75 }
76  
77 sub _get_matched_parsers {
78 3308 ▶ my ( $self, $type, $l ) = @_;
Subroutine _get_matched_parsers: called CC=8 SCAR=20.8
79 3308 my $c = $self->context;
80 3308 $type .= '_parsers';
81  
82 3308 my @matched_parsers;
83  
84 3308 for my $parser ( @{ $self->$type } ) {
85 next
86 18140 ▶ if ( grep { ref($parser) eq 'Text::Trac::' . $self->_camelize($_) } @{ $c->in_block_of }
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $parser eq 'Text::Trac::' . $self->_camelize($_);} @{$c->in_block_of;} and $type =~ /^block/ 236 17904 18140
Condition66%2/3
grep {ref $parser eq 'Text::Trac::' . $self->_camelize($_);} @{$c->in_block_of;} and $type =~ /^block/
!ll&&!rl&&r
179040236
MC/DC50%1/2
grep {ref $parser eq 'Text::Trac::' . $self->_camelize($_);} @{$c->in_block_of;} and $type =~ /^block/
grep {ref $parser eq 'Text::Trac::' . $self->_camelize($_);} @{$c->in_block_of;} $type =~ /^block/
Truth table66%2/3
A and B
A= grep {ref $parser eq 'Text::Trac::' . $self->_camelize($_);} @{$c->in_block_of;}B= $type =~ /^block/
ABresult
0X0
100
111
87 and $type =~ /^block/ );
88 17904 ▶ my $pattern = $parser->pattern or next;
Branch: 1 branch
BranchTrueFalseTotal
my $pattern = $parser->pattern or next 1650 16254 17904
89  
90 16254 ▶ if ( $l =~ /$pattern/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /$pattern/) 952 15302 16254
91 952 push @matched_parsers, $parser;
92 }
93 }
94  
95 3308 ▶ push @matched_parsers, Text::Trac::P->new( { context => $self->context } )
Branch: 1 branch
BranchTrueFalseTotal
if not @matched_parsers and $type =~ /^block/ 2346 962 3308
Condition100%3/3
not @matched_parsers and $type =~ /^block/
!ll&&!rl&&r
949132346
MC/DC100%2/2
not @matched_parsers and $type =~ /^block/
not @matched_parsers $type =~ /^block/
Truth table100%3/3
not(A) and B
A= not @matched_parsersB= $type =~ /^block/
ABresult
0X0
100
111
96 if ( !@matched_parsers and $type =~ /^block/ );
97 3308 return \@matched_parsers;
98 }
99  
100 sub _camelize {
101 7262 ▶ my ( $self, $word ) = @_;
Subroutine _camelize: called CC=2 SCAR=6.9
102  
103 7262 my $camelized_word;
104 7262 for ( split '_', $word ) {
105 7262 chomp($_);
106 7262 $camelized_word .= ucfirst($_);
107 }
108  
109 7262 return $camelized_word;
110 }
111  
112 53 1;
« blib/lib/Text/Trac/Ol.pm ↑ Summary blib/lib/Text/Trac/Ul.pm »