| 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
| |||||||||||||||||||||||||||||
| 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'} || ''
MC/DC100%1/1
delete $args{'text'} || ''
delete $args{'text'}
Truth table100%2/2
A
A= delete $args{'text'}
| |||||||||||||||||||||||||||||
| 34 | 68 | ▶ | $args{args} = [ $class->arg_to_ref( delete $args{args} || [] ) ]; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'args'} || []
MC/DC100%1/1
delete $args{'args'} || []
delete $args{'args'}
Truth table100%2/2
A
A= delete $args{'args'}
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
builtin::reftype($value) || ''
MC/DC100%1/1
builtin::reftype($value) || ''
builtin::reftype($value)
Truth table100%2/2
A
A= builtin::reftype($value)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 105 | 30 | ▶ | return $next_block unless $self->level() == $next_block->level(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 123 | 25 | ▶ | return $next_block unless $self->nests() and $next_block->nests(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->nests and $next_block->nests
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
| |||||||||||||||||||||||||||||
| 124 | 2 | ▶ | return $next_block unless $self->level() < $next_block->level(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||