RegGrp/Data.pm

filter: Statementstmt 100% 52 / 52 Branchbran 90.9% 20 / 22 Conditioncond 88.8% 16 / 18 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 92.0% 104 / 113 CC 18 SCAR 25.8
CC
18
Cov
96%
new
18.0
BEGIN
1.0
BEGIN
1.0
CRAP 13.3
↑ Summary RegGrp.pm »
1 package Regexp::RegGrp::Data;
2  
3 4 ▶use 5.008009;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our @ACCESSORS = ( 'regexp', 'replacement', 'store', 'restore_pattern' );
9  
10 ##########################################################################################
11  
12 {
13 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 foreach my $field ( @ACCESSORS ) {
16 16 ▶ next if defined *{'Regexp::RegGrp::Data::' . $field}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
if defined *{'Regexp::RegGrp::Data::' . $field;}{"CODE"} 0 16 16
17  
18 16 *{'Regexp::RegGrp::Data::' . $field} = sub {
19 428 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 428 return $self->{'_' . $field};
22 16 };
23 }
24 }
25  
26 sub new {
27 68 ▶ my ( $class, $in_ref ) = @_;
Subroutine new: called CC=18 SCAR=28.9
Pod undocumented
28 68 my $self = {};
29  
30 68 bless( $self, $class );
31  
32 68 ▶ unless ( $in_ref->{regexp} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in_ref->{"regexp"}) 2 66 68
33 2 carp( 'Value for key "regexp" must be a scalar or a regexp object!' );
34 2 return;
35 }
36  
37 66 foreach my $accessor ( @ACCESSORS ) {
38 252 ▶ if ( $accessor eq 'regexp' || $accessor eq 'restore_pattern' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($accessor eq 'regexp' or $accessor eq 'restore_pattern') { } 126 126 252
elsif ($accessor eq 'replacement' or $accessor eq 'store') { } 126 0 126
Condition100%3/3
$accessor eq "regexp" or $accessor eq "restore_pattern"
l!l&&r!l&&!r
6660126
MC/DC100%2/2
$accessor eq "regexp" or $accessor eq "restore_pattern"
$accessor eq "regexp" $accessor eq "restore_pattern"
Truth table100%3/3
A or B
A= $accessor eq "regexp"B= $accessor eq "restore_pattern"
ABresult
1X1
011
000
39 126 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in_ref->{$accessor} and ref $in_ref->{$accessor} ne "Regexp") 4 122 126
Condition100%3/3
ref $in_ref->{$accessor} and ref $in_ref->{$accessor} ne "Regexp"
!ll&&!rl&&r
83394
MC/DC100%2/2
ref $in_ref->{$accessor} and ref $in_ref->{$accessor} ne "Regexp"
ref $in_ref->{$accessor} ref $in_ref->{$accessor} ne "Regexp"
Truth table100%3/3
A and B
A= ref $in_ref->{$accessor}B= ref $in_ref->{$accessor} ne "Regexp"
ABresult
0X0
100
111
40 ref( $in_ref->{$accessor} ) and
41 ref( $in_ref->{$accessor} ) ne 'Regexp'
42 ) {
43 4 carp( 'Value for key "' . $accessor . '" must be a scalar or a regexp object!' );
44 4 return;
45 }
46 }
47 ▶ elsif ( $accessor eq 'replacement' || $accessor eq 'store' ) {
Condition66%2/3
$accessor eq "replacement" or $accessor eq "store"
l!l&&r!l&&!r
64620
MC/DC0%0/2
$accessor eq "replacement" or $accessor eq "store"
$accessor eq "replacement" $accessor eq "store"
Truth table66%2/3
A or B
A= $accessor eq "replacement"B= $accessor eq "store"
ABresult
1X1
011
000
48 126 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in_ref->{$accessor} and ref $in_ref->{$accessor} ne "CODE") 4 122 126
Condition100%3/3
ref $in_ref->{$accessor} and ref $in_ref->{$accessor} ne "CODE"
!ll&&!rl&&r
92304
MC/DC100%2/2
ref $in_ref->{$accessor} and ref $in_ref->{$accessor} ne "CODE"
ref $in_ref->{$accessor} ref $in_ref->{$accessor} ne "CODE"
Truth table100%3/3
A and B
A= ref $in_ref->{$accessor}B= ref $in_ref->{$accessor} ne "CODE"
ABresult
0X0
100
111
49 ref( $in_ref->{$accessor} ) and
50 ref( $in_ref->{$accessor} ) ne 'CODE'
51 ) {
52 4 carp( 'Value for key "' . $accessor . '" must be a scalar or a code reference!' );
53 4 return;
54 }
55 }
56 }
57  
58 58 ▶ if ( ref( $in_ref->{modifier} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in_ref->{"modifier"}) 2 56 58
59 2 carp( 'Value for key "modifier" must be a scalar!' );
60 2 return;
61 }
62  
63 56 $self->{_regexp} = $in_ref->{regexp};
64 $self->{_replacement} = defined( $in_ref->{store} ) ? (
65 $in_ref->{restore_pattern} ? $in_ref->{replacement} : sub {
66 9 ▶ return sprintf( "\x01%d\x01", $_[0]->{store_index} );
Subroutine __ANON__: called CC=1 SCAR=0.0
67 }
68 56 ▶ ) : $in_ref->{replacement};
Branch: 2 branches
BranchTrueFalseTotal
defined $in_ref->{'store'} ? : 13 43 56
$in_ref->{'restore_pattern'} ? : 5 8 13
69 56 $self->{_store} = $in_ref->{store};
70  
71 56 ▶ if ( defined( $in_ref->{modifier} ) || ! ref( $in_ref->{regexp} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $in_ref->{"modifier"} or not ref $in_ref->{"regexp"}) 25 31 56
Condition100%3/3
defined $in_ref->{"modifier"} or not ref $in_ref->{"regexp"}
l!l&&r!l&&!r
81731
MC/DC100%2/2
defined $in_ref->{"modifier"} or not ref $in_ref->{"regexp"}
defined $in_ref->{"modifier"} not ref $in_ref->{"regexp"}
Truth table100%3/3
A or not(B)
A= defined $in_ref->{"modifier"}B= not ref $in_ref->{"regexp"}
ABresult
1X1
011
000
72 25 ▶ my $modifier = defined( $in_ref->{modifier} ) ? $in_ref->{modifier} : 'sm';
Branch: 1 branch
BranchTrueFalseTotal
defined $in_ref->{'modifier'} ? : 8 17 25
73  
74 25 $self->{_regexp} =~ s/^\(\?[\^dlupimsx-]+:(.*)\)$/$1/si;
75 25 $self->{_regexp} = sprintf( '(?%s:%s)', $modifier, $self->{_regexp} );
76 }
77  
78 56 ▶ my $restore_pattern = $in_ref->{restore_pattern} || qr~\x01(\d+)\x01~;
Condition66%2/3
$in_ref->{'restore_pattern'} || qr/\x01(\d+)\x01/
l!l&&r!l&&!r
9470
MC/DC0%0/2
$in_ref->{'restore_pattern'} || qr/\x01(\d+)\x01/
$in_ref->{'restore_pattern'} qr/\x01(\d+)\x01/
Truth table66%2/3
A || B
A= $in_ref->{'restore_pattern'}B= qr/\x01(\d+)\x01/
ABresult
1X1
011
000
79 56 $self->{_restore_pattern} = qr/$restore_pattern/;
80  
81 56 return $self;
82 }
83  
84 4 1;
↑ Summary RegGrp.pm »