blib/lib/PerlX/QuoteOperator/Inescapable.pm

filter: Statementstmt 72.1% 44 / 61 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 76.4% 13 / 17 Podpod n/a totaltotal 65.6% 63 / 96 CC 8 SCAR 11.2
CC
8
Cov
67%
import
6.2
_ender
6.0
_parser
4.0
CRAP 3.1
↑ Summary
1 package PerlX::QuoteOperator::Inescapable;
2  
3 3 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶no warnings qw( void once uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 $PerlX::QuoteOperator::Inescapable::AUTHORITY = 'cpan:TOBYINK';
10 3 $PerlX::QuoteOperator::Inescapable::VERSION = '0.002';
11 }
12  
13 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Devel::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Data::OptList;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Sub::Install qw/install_sub/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use parent qw/Devel::Declare::Context::Simple/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 sub import
21 3 ▶{
Subroutine import: called CC=6 SCAR=18.3
22 3 my $caller = caller;
23 3 my $self = shift;
24
25 3 ▶ @_ = 'Q' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 1 3
26 3 my $optlist = Data::OptList::mkopt(\@_);
27
28 3 for my $opt ( @$optlist )
29 {
30 3 my ($declarator, $callback) = @$opt;
31 0 ▶ $callback //= sub ($) { +shift };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Condition66%2/3
$callback //= sub ($) { shift(); }
l!l&&r!l&&!r
120
MC/DC0%0/2
$callback //= sub ($) { shift(); }
$callback sub ($) { shift(); }
Truth table66%2/3
A //= B
A= $callbackB= sub ($) { shift(); }
ABresult
1X1
011
000
32 3 ▶ $callback = delete $callback->{'-with'} if ref $callback eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback eq "HASH" 0 3 3
33
34 3 ▶ $self = $self->new unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 3 0 3
35 Devel::Declare->setup_for(
36 $caller,
37 5 ▶ { $declarator => { const => sub { $self->_parser(@_) } } }
Subroutine __ANON__: called CC=1 SCAR=0.0
38 3 );
39
40 3 install_sub {
41 into => $caller,
42 as => $declarator,
43 code => $callback,
44 };
45 }
46 }
47  
48 sub unimport
49 0 ▶{
Subroutine unimport: not called CC=1 SCAR=6.9
50 0 $^H{(__PACKAGE__)} = undef;
51 }
52  
53 sub _parser
54 5 ▶{
Subroutine _parser: called CC=2 SCAR=14.0
55 5 my $self = shift;
56 5 $self->init(@_);
57
58 5 $self->skip_declarator;
59 0 $self->skipspace;
60
61 0 my $linestr = $self->get_linestr;
62
63 0 my $remaining = substr($linestr, $self->offset);
64 0 my $starter = substr($remaining, 0, 1);
65 0 my $ender = $self->_ender($starter);
66
67 0 my $ending = index($remaining, $ender, 1);
68 0 ▶ croak "Unterminated inescapable quoted string found: '$remaining'" if $ending < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ending < 0 0 0 0
69
70 0 substr($remaining, 0, $ending+1) = sprintf("('%s')", $self->_quote(substr $remaining, 1, $ending-1));
71 0 substr($linestr, $self->offset) = $remaining;
72
73 0 $self->set_linestr($linestr);
74 }
75  
76 sub _ender
77 0 ▶{
Subroutine _ender: not called CC=2 SCAR=17.9
78 0 my ($self, $str) = @_;
79 {
80 '(' => ')',
81 '{' => '}',
82 '[' => ']',
83 '<' => '>',
84 0 ▶ }->{$str} // $str;
Condition0%0/3
{"(", ")", "{", "}", "[", "]", "<", ">"}->{$str} // $str
l!l&&r!l&&!r
000
MC/DC0%0/2
{"(", ")", "{", "}", "[", "]", "<", ">"}->{$str} // $str
{"(", ")", "{", "}", "[", "]", "<", ">"}->{$str} $str
Truth table0%0/3
A // B
A= {"(", ")", "{", "}", "[", "]", "<", ">"}->{$str}B= $str
ABresult
1X1
011
000
85 }
86  
87 sub _quote
88 0 ▶{
Subroutine _quote: not called CC=1 SCAR=6.9
89 0 my ($self, $str) = @_;
90 0 $str =~ s{([\\\'])}{\\$1}g;
91 0 return $str;
92 }
93  
94 3 __FILE__
95 __END__
↑ Summary