File Coverage

blib/lib/Parse/Highlife/Token/Regex.pm
Criterion Covered Total %
statement 9 22 40.9
branch 0 2 0.0
condition n/a
subroutine 3 6 50.0
pod 0 2 0.0
total 12 32 37.5


line stmt bran cond sub pod time code
1             package Parse::Highlife::Token::Regex;
2              
3 1     1   6 use base qw(Parse::Highlife::Token);
  1         1  
  1         539  
4 1     1   85 use Parse::Highlife::Utils qw(params extend_match);
  1         2  
  1         44  
5              
6 1     1   5 use Data::Dump qw(dump);
  1         2  
  1         280  
7              
8             sub new
9             {
10 0     0 0   my( $class, @args ) = @_;
11 0           my $self = bless Parse::Highlife::Token->new( @args ), $class;
12 0           return $self -> _init( @args );
13             }
14              
15             sub _init
16             {
17 0     0     my( $self, $regex )
18             = params( \@_,
19             -regex => '',
20             );
21 0           $self->{'regex'} = $regex;
22 0           return $self;
23             }
24              
25             sub match
26             {
27 0     0 0   my( $self, $string, $offset ) = @_;
28 0           my $tail = substr $string, $offset;
29 0           my $regex = '^('.$self->{'regex'}.')';
30 0 0         if( $tail =~ /$regex/ ) {
31 0           my ($match) = $tail =~ /$regex/;
32             return
33 0           extend_match(
34             $string,
35             {
36             'token-classname' => ref $self,
37             'matched-substring' => $match,
38             'first-offset' => $offset,
39             }
40             );
41             }
42 0           return 0;
43             }
44              
45             1;