Chain/Builder.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Chain.pm ↑ Summary Chain/Carp.pm »
1 package Getopt::Chain::Builder;
2  
3 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Getopt::Chain::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Path::Dispatcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Path::Dispatcher::Builder;
Subroutine BEGIN: called CC=1 SCAR=2.6
8  
9 has builder => qw/is ro lazy_build 1/, handles => [qw/ dispatcher rewrite /];
10 sub _build_builder {
11 my $self = shift;
12 return Path::Dispatcher::Builder->new;
13 }
14  
15 sub start {
16 my $self = shift;
17 $self->on( '' => shift, shift);
18 }
19  
20 sub on {
21 my $self = shift;
22 my $path = shift;
23 my $argument_schema = shift;
24 my $run = shift;
25 my %given = @_;
26  
27 my %control = (
28 map { $_ => $given{$_} } grep { exists $given{$_} } qw/always_run/
29 );
30
31
32 my $matcher;
33 if (ref $path eq 'ARRAY') {
34 $matcher = $path;
35 }
36 elsif (ref $path eq 'Regexp') {
37 $matcher = $path;
38 }
39 elsif (! ref $path) {
40 # Also, check for '*', '$', etc. Ignore if literal => 1
41 if ($path eq '') { # The start rule, special case
42 $control{always_run} = 1 unless exists $given{always_run};
43 $matcher = [];
44 }
45 elsif ($path =~ s/\s+\*\s*$//) {
46 $matcher = qr/$path\b(.*)/;
47 $control{arguments_from_1} = 1;
48 }
49 elsif ($path =~ m/^\s*\*\s*$/) {
50 $matcher = qr/(.*)/;
51 $control{arguments_from_1} = 1;
52 }
53 else {
54 $matcher = [ split m/\s+/, $path ];
55 }
56
57 }
58 else {
59 croak "Don't recogonize matcher ($path)";
60 }
61 $self->builder->on( $matcher, sub { # The builder should do the split for us!
62 my $context = shift;
63 return $context->run_step( $argument_schema, $run, { %control } );
64 } );
65 }
66  
67 sub under {
68 my $self = shift;
69 $self->builder->under( @_ );
70 }
71  
72 1;
« Chain.pm ↑ Summary Chain/Carp.pm »