File Coverage

blib/lib/Data/Object/Regexp/Result.pm
Criterion Covered Total %
statement 54 54 100.0
branch n/a
condition 9 16 56.2
subroutine 14 14 100.0
pod 11 11 100.0
total 88 95 92.6


line stmt bran cond sub pod time code
1             # ABSTRACT: A Regexp Result Object for Perl 5
2             package Data::Object::Regexp::Result;
3              
4 7     7   131 use 5.010;
  7         18  
  7         378  
5 7     7   32 use Data::Object::Class;
  7         10  
  7         45  
6              
7 7     7   1613 use Data::Object 'deduce_deep';
  7         12  
  7         3761  
8              
9             extends 'Data::Object::Array';
10              
11             our $VERSION = '0.20'; # VERSION
12              
13             sub captures {
14 2     2 1 578 my $self = shift;
15 2         8 my $string = $self->initial;
16              
17 2         10 my $last_match_start = $self->last_match_start;
18 2         9 my $last_match_end = $self->last_match_end;
19              
20 2         5 my @captures;
21              
22 2         9 for (my $i = 1; $i < @$last_match_end; $i++) {
23 4   100     89 my $start = $last_match_start->[$i] || 0;
24 4   50     17 my $end = $last_match_end->[$i] || 0;
25              
26 4         82 push @captures, substr "$string", $start, $end - $start;
27             }
28              
29 2         11 return deduce_deep [@captures];
30             }
31              
32             sub count {
33 2     2 1 14 my $self = shift;
34 2         10 return deduce_deep $self->[2];
35             }
36              
37             sub initial {
38 5     5 1 11 my $self = shift;
39 5         22 return deduce_deep $self->[6];
40             }
41              
42             sub last_match_end {
43 5     5 1 10 my $self = shift;
44 5         15 return deduce_deep $self->[4];
45             }
46              
47             sub last_match_start {
48 5     5 1 10 my $self = shift;
49 5         18 return deduce_deep $self->[3];
50             }
51              
52             sub named_captures {
53 6     6 1 20 my $self = shift;
54 6         24 return deduce_deep $self->[5];
55             }
56              
57             sub matched {
58 1     1 1 2 my $self = shift;
59 1         74 my $string = $self->initial;
60              
61 1         4 my $last_match_start = $self->last_match_start;
62 1         4 my $last_match_end = $self->last_match_end;
63              
64 1   50     52 my $start = $last_match_start->[0] || 0;
65 1   50     2 my $end = $last_match_end->[0] || 0;
66              
67 1         50 return deduce_deep substr "$string", $start, $end - $start;
68             }
69              
70             sub prematched {
71 1     1 1 3 my $self = shift;
72 1         5 my $string = $self->initial;
73              
74 1         5 my $last_match_start = $self->last_match_start;
75 1         5 my $last_match_end = $self->last_match_end;
76              
77 1   50     6 my $start = $last_match_start->[0] || 0;
78 1   50     5 my $end = $last_match_end->[0] || 0;
79              
80 1         4 return deduce_deep substr "$string", 0, $start;
81             }
82              
83             sub postmatched {
84 1     1 1 3 my $self = shift;
85 1         5 my $string = $self->initial;
86              
87 1         5 my $last_match_start = $self->last_match_start;
88 1         4 my $last_match_end = $self->last_match_end;
89              
90 1   50     7 my $start = $last_match_start->[0] || 0;
91 1   50     5 my $end = $last_match_end->[0] || 0;
92              
93 1         6 return deduce_deep substr "$string", $end;
94             }
95              
96             sub regexp {
97 1     1 1 3 my $self = shift;
98 1         6 return deduce_deep $self->[0];
99             }
100              
101             sub string {
102 5     5 1 493 my $self = shift;
103 5         28 return deduce_deep $self->[1];
104             }
105              
106             1;
107              
108             __END__