| 1 | package Text::Xatena::Inline::Base; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 20 | ▶ | use List::MoreUtils qw(any); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 66 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 8 | 66 | my $class = shift; | |||||||||||||||||||
| 9 | 66 | my $caller = caller(0); | |||||||||||||||||||
| 10 | 66 | ▶ | if (any { $_ eq '-Base' } @_) { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||
| 11 | 20 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 23 | push @{"$caller\::ISA"}, $class; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 23 | for my $method (qw/match/) { | |||||||||||||||||||
| 15 | 20 | ▶ | no warnings 'redefine'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 23 | *{"$caller\::$method"} = \&{"$class\::$method"}; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 592 | ▶ | sub inlines { | ||||||||||||||||||
|
Subroutine
inlines: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 22 | 592 | my ($caller) = @_; | |||||||||||||||||||
| 23 | 592 | ▶ | $caller = ref($caller) || $caller; | ||||||||||||||||||
|
Condition66%2/3
ref $caller || $caller
MC/DC0%0/2
ref $caller || $caller
ref $caller
$caller
Truth table66%2/3
A || B
A= ref $callerB= $caller
| |||||||||||||||||||||
| 24 | 20 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 592 | ▶ | ${$caller.'::_inlines'} ||= do { | ||||||||||||||||||
|
Condition66%2/3
${$caller . '::_inlines';} ||= do {
my $parents = [];
foreach my $isa (@{$caller . '::ISA';}) {
my $isa = $isa->inlines;
push @$parents, @$isa;
};
$parents
}
MC/DC0%0/2
${$caller . '::_inlines';} ||= do {
my $parents = [];
foreach my $isa (@{$caller . '::ISA';}) {
my $isa = $isa->inlines;
push @$parents, @$isa;
};
$parents
}
${$caller . '::_inlines';}
do {
my $parents = [];
foreach my $isa (@{$caller . '::ISA';}) {
my $isa = $isa->inlines;
push @$parents, @$isa;
};
$parents
}
Truth table66%2/3
A ||= B
A= ${$caller . '::_inlines';}B= do {
my $parents = [];
foreach my $isa (@{$caller . '::ISA';}) {
my $isa = $isa->inlines;
push @$parents, @$isa;
};
$parents
}
| |||||||||||||||||||||
| 26 | 43 | my $parents = []; | |||||||||||||||||||
| 27 | 43 | for my $isa (@{$caller.'::ISA'}) { | |||||||||||||||||||
| 28 | 23 | my $isa = $isa->inlines; | |||||||||||||||||||
| 29 | 23 | push @$parents, @$isa; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | 43 | $parents; | |||||||||||||||||||
| 32 | }; | ||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 222 | ▶ | sub match ($$) { ## no critic | ||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 36 | 222 | my ($regexp, $block) = @_; | |||||||||||||||||||
| 37 | 222 | my $pkg = caller(0); | |||||||||||||||||||
| 38 | 222 | push @{ $pkg->inlines }, { regexp => $regexp, block => $block }; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 125 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 42 | 125 | my ($class, %opts) = @_; | |||||||||||||||||||
| 43 | 125 | bless { | |||||||||||||||||||
| 44 | %opts | ||||||||||||||||||||
| 45 | }, $class; | ||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 281 | ▶ | sub format { | ||||||||||||||||||
|
Subroutine
format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 49 | 281 | my ($self, $text) = @_; | |||||||||||||||||||
| 50 | 281 | $text =~ s{^\n}{}g; | |||||||||||||||||||
| 51 | 281 | my $re = join("|", map { $_->{regexp} } @{ $self->inlines }); | |||||||||||||||||||
| 52 | 281 | $text =~ s{($re)}{$self->_format($1)}eg; | |||||||||||||||||||
| 53 | 281 | $text; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 66 | ▶ | sub _format { | ||||||||||||||||||
|
Subroutine
_format: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 57 | 66 | my ($self, $string) = @_; | |||||||||||||||||||
| 58 | 66 | for my $inline (@{ $self->inlines }) { | |||||||||||||||||||
| 59 | 463 | ▶ | if (my @matched = ($string =~ $inline->{regexp})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 66 | $string = $inline->{block}->($self, @matched); | |||||||||||||||||||
| 61 | 66 | last; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | 66 | $string; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 20 | 1; | |||||||||||||||||||