WikiFormat/Blocks.pm

filter: Statementstmt 100% 78 / 78 Branchbran 87.5% 21 / 24 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 22 / 22 Podpod n/a totaltotal 97.8% 135 / 138 CC 17 SCAR 9.3
CC
17
Cov
97%
nest
6.0
new
3.0
arg_to_ref
3.0
CRAP 2.5
« WikiFormat.pm ↑ Summary
1 package Text::WikiFormat::Blocks;
2  
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub import
7 14 ▶{
Subroutine import: called CC=1 SCAR=0.0
8 14 my $caller = caller();
9 14 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 *{ $caller . '::new_block' } = sub
11 268 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
12 268 my $type = shift;
13 268 my $class = "Text::WikiFormat::Block::$type";
14 268 my $ctor;
15
16 268 ▶ unless ($ctor = $class->can( 'new' ))
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctor = $class->can("new")) 41 227 268
17 {
18 41 @{ $class . '::ISA' } = ( 'Text::WikiFormat::Block' );
19 41 $ctor = $class->can( 'new' );
20 }
21  
22 268 return $class->new( type => $type, @_ );
23 14 };
24 }
25  
26 package Text::WikiFormat::Block;
27  
28 14 ▶use Scalar::Util qw( blessed reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 sub new
31 268 ▶{
Subroutine new: called CC=3 SCAR=11.0
32 268 my ($class, %args) = @_;
33  
34 268 ▶ $args{text} = $class->arg_to_ref( delete $args{text} || '' );
Condition100%2/2
delete $args{'text'} || ''
l!l
17989
MC/DC100%1/1
delete $args{'text'} || ''
delete $args{'text'}
Truth table100%2/2
A
A= delete $args{'text'}
Aresult
11
00
35 268 ▶ $args{args} = [ $class->arg_to_ref( delete $args{args} || [] ) ];
Condition100%2/2
delete $args{'args'} || []
l!l
18286
MC/DC100%1/1
delete $args{'args'} || []
delete $args{'args'}
Truth table100%2/2
A
A= delete $args{'args'}
Aresult
11
00
36  
37 268 bless \%args, $class;
38 }
39  
40 sub arg_to_ref
41 536 ▶{
Subroutine arg_to_ref: called CC=3 SCAR=11.0
42 536 my ($class, $value) = @_;
43 536 ▶ return $value if ( reftype( $value ) || '' ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($value) || "") eq "ARRAY" 274 262 536
Condition100%2/2
builtin::reftype($value) || ''
l!l
274262
MC/DC100%1/1
builtin::reftype($value) || ''
builtin::reftype($value)
Truth table100%2/2
A
A= builtin::reftype($value)
Aresult
11
00
44 262 return [ $value ];
45 }
46  
47 sub shift_args
48 36 ▶{
Subroutine shift_args: called CC=2 SCAR=7.0
49 36 my $self = shift;
50 36 my $args = shift @{ $self->{args} };
51 36 ▶ return wantarray ? @$args : $args;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 36 0 36
52 }
53  
54 sub all_args
55 64 ▶{
Subroutine all_args: called CC=2 SCAR=7.2
56 64 my $args = $_[0]{args};
57 64 ▶ return wantarray ? @$args : $args;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 64 0 64
58 }
59  
60 sub text
61 196 ▶{
Subroutine text: called CC=2 SCAR=7.2
62 196 my $text = $_[0]{text};
63 196 ▶ return wantarray ? @$text : $text;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 196 0 196
64 }
65  
66 sub add_text
67 74 ▶{
Subroutine add_text: called CC=1 SCAR=0.0
68 74 my $self = shift;
69 74 push @{ $self->{text} }, @_;
70 }
71  
72 sub formatted_text
73 116 ▶{
Subroutine formatted_text: called CC=2 SCAR=6.9
74 116 my $self = shift;
75 return map
76 {
77 116 ▶ blessed( $_ ) ? $_ : $self->formatter( $_ )
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) ? : 11 184 195
78 } $self->text();
79 }
80  
81 sub formatter
82 171 ▶{
Subroutine formatter: called CC=1 SCAR=0.0
83 171 my ($self, $line) = @_;
84 171 Text::WikiFormat::format_line( $line, $self->tags(), $self->opts() );
85 }
86  
87 sub add_args
88 64 ▶{
Subroutine add_args: called CC=1 SCAR=0.0
89 64 my $self = shift;
90 64 push @{ $self->{args} }, @_;
91 }
92  
93 {
94 14 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 14 for my $attribute (qw( level opts tags type ))
96 {
97 1795 ▶ *{ $attribute } = sub { $_[0]{$attribute} };
Subroutine __ANON__: called CC=1 SCAR=0.0
98 }
99 }
100  
101 sub merge
102 360 ▶{
Subroutine merge: called CC=3 SCAR=11.0
103 360 my ($self, $next_block) = @_;
104  
105 360 ▶ return $next_block unless $self->type() eq $next_block->type();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->type eq $next_block->type 270 90 360
106 90 ▶ return $next_block unless $self->level() == $next_block->level();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->level == $next_block->level 26 64 90
107  
108 64 $self->add_text( $next_block->text() );
109 64 $self->add_args( $next_block->all_args() );
110 64 return;
111 }
112  
113 sub nests
114 186 ▶{
Subroutine nests: called CC=1 SCAR=0.0
115 186 my $self = shift;
116 186 return exists $self->{tags}{nests}{ $self->type() };
117 }
118  
119 sub nest
120 151 ▶{
Subroutine nest: called CC=6 SCAR=17.9
121 151 my ($self, $next_block) = @_;
122  
123 151 ▶ return unless $next_block = $self->merge( $next_block );
Branch: 1 branch
BranchTrueFalseTotal
unless $next_block = $self->merge($next_block) 5 146 151
124 146 ▶ return $next_block unless $self->nests() and $next_block->nests();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->nests and $next_block->nests 133 13 146
Condition100%3/3
$self->nests and $next_block->nests
!ll&&!rl&&r
1062713
MC/DC100%2/2
$self->nests and $next_block->nests
$self->nests $next_block->nests
Truth table100%3/3
A and B
A= $self->nestsB= $next_block->nests
ABresult
0X0
100
111
125 13 ▶ return $next_block unless $self->level() < $next_block->level();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->level < $next_block->level 1 12 13
126  
127 # if there's a nested block at the end, maybe it can nest too
128 12 my $last_item = ( $self->text() )[-1];
129 12 ▶ return $last_item->nest( $next_block ) if blessed( $last_item );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($last_item) 2 10 12
130  
131 10 $self->add_text( $next_block );
132 10 return;
133 }
134  
135 package Text::WikiFormat::Block::code;
136  
137 14 ▶use base 'Text::WikiFormat::Block';
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 13 ▶sub formatter { $_[1] }
Subroutine formatter: called CC=1 SCAR=0.0
140  
141 package Text::WikiFormat::Blocks;
142  
143 14 1;
144 __END__
« WikiFormat.pm ↑ Summary