File Coverage

blib/lib/Data/Object/Role/Regexp.pm
Criterion Covered Total %
statement 36 36 100.0
branch 2 4 50.0
condition 3 4 75.0
subroutine 6 6 100.0
pod 0 2 0.0
total 47 52 90.3


line stmt bran cond sub pod time code
1             # ABSTRACT: Regexp Object Role for Perl 5
2             package Data::Object::Role::Regexp;
3              
4 7     7   4113 use 5.010;
  7         19  
5 7     7   31 use Data::Object::Role;
  7         10  
  7         92  
6              
7 7     7   1949 use Data::Object 'throw';
  7         11  
  7         2327  
8              
9             map with($_), our @ROLES = qw(
10             Data::Object::Role::Defined
11             Data::Object::Role::Detract
12             Data::Object::Role::Output
13             Data::Object::Role::Ref
14             Data::Object::Role::Type
15             );
16              
17             our $VERSION = '0.41'; # VERSION
18              
19             sub search {
20 6     6 0 13 my($self, $string, $flags) = @_;
21              
22 6         10 my $captures;
23             my @matches;
24              
25 6         11 my $op = '$string =~ m/$$self/';
26 6   50     40 my $capt = '$captures = (' . $op . ($flags // '') . ')';
27 6         8 my $mtch = '@matches = ([@-], [@+], {%-})';
28 6         17 my $expr = join ';', $capt, $mtch;
29              
30 6         9 my $error = do { local $@; eval $expr; $@ };
  6         10  
  6         785  
  6         35  
31 6 50       24 throw $error if $error;
32              
33 6         83 return [$$self, $string, $captures, @matches, $string];
34             }
35              
36             sub replace {
37 4     4 0 9 my($self, $string, $replacement, $flags) = @_;
38              
39 4         5 my $captures;
40             my @matches;
41              
42 4         4 my $op = '$string =~ s/$$self/$replacement/';
43 4   100     23 my $capt = '$captures = (' . $op . ($flags // '') . ')';
44 4         4 my $mtch = '@matches = ([@-], [@+], {%-})';
45 4         8 my $expr = join ';', $capt, $mtch;
46              
47 4         4 my $initial = $string;
48              
49 4     2   4 my $error = do { local $@; eval $expr; $@ };
  4         5  
  4         337  
  4         16  
  2         1389  
  2         937  
  2         43  
50 4 50       10 throw $error if $error;
51              
52 4         36 return [$$self, $string, $captures, @matches, $initial];
53             }
54              
55             1;
56              
57             __END__