GooglewikiFormat/Blocks.pm

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