blib/lib/Lingy/Regex.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 44 CC 3 SCAR 16.1
CC
3
Cov
0%
find
12.0
new
2.0
matches
2.0
CRAP 5.0
1 use strict; use warnings;
2 package Lingy::Regex;
3  
4 use Lingy::Common;
5  
6 # need these things:
7 # * if-some
8 # * "sequence destructuring bindings"
9  
10 sub new {
11 my ($class, $scalar) = @_;
12 bless qr/$scalar/, $class;
13 }
14  
15 sub find {
16 return nil unless $_[1] =~ $_[0];
17 return string($&) unless defined $1;
18 my ($i, @capture) = (1, string($&));
19 {
20 no strict 'refs';
21 while (defined (my $value = ${"$i"})) {
22 push @capture, string($value);
23 $i++;
24 }
25 }
26 VECTOR->new([@capture]);
27 }
28  
29 sub matches {
30 find REGEX->new("\\A$_[0]\\z"), $_[1];
31 }
32  
33 sub pattern {
34 __PACKAGE__->new(@_);
35 }
36  
37 1;