| 1 | package Config::Maker::Option; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 9 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 9 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 9 | ▶ | use Config::Maker; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 9 | ▶ | use Config::Maker::Type; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 9 | ▶ | use Config::Maker::Path; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | use overload | ||||||||||||||
| 14 | 9 | ▶ | 'cmp' => \&Config::Maker::truecmp, | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.3
| |||||||||||||||
| 15 | '<=>' => \&Config::Maker::truecmp, | ||||||||||||||
| 16 | 672 | ▶ | '""' => sub { $_[0]->{-value}; }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 0 | ▶ | '/' => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||
| 18 | 0 | ▶ | croak "Can't \"divide by\" option" if $_[2]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | 0 | $_[0]->get($_[1]); | |||||||||||||
| 20 | }, | ||||||||||||||
| 21 | 0 | ▶ | '&{}' => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 22 | 0 | my $self = $_[0]; | |||||||||||||
| 23 | 0 | ▶ | sub { $self->get(@_); }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 24 | }, | ||||||||||||||
| 25 | 9 | fallback => 1; | |||||||||||||
| 26 | |||||||||||||||
| 27 | 3036 | ▶ | sub _ref(\%$;$) { | ||||||||||||
|
Subroutine
_ref: called CC=3 SCAR=11.2
| |||||||||||||||
| 28 | 3036 | my ($hash, $key, $default) = @_; | |||||||||||||
| 29 | 3036 | ▶ | if(exists $hash->{$key}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 30 | 2111 | my $rv = $hash->{$key}; | |||||||||||||
| 31 | 2111 | delete $hash->{$key}; | |||||||||||||
| 32 | 2111 | return $rv; | |||||||||||||
| 33 | } elsif(@_ == 3) { | ||||||||||||||
| 34 | 925 | return $default; | |||||||||||||
| 35 | } else { | ||||||||||||||
| 36 | 0 | croak "Mandatory argument $key not specified"; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 1021 | ▶ | sub _flatten { | ||||||||||||
|
Subroutine
_flatten: called CC=2 SCAR=6.9
| |||||||||||||||
| 41 | map { | ||||||||||||||
| 42 | 1021 | ▶ | ref($_) eq 'ARRAY' ? | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | _flatten(@$_) : | ||||||||||||||
| 44 | $_; | ||||||||||||||
| 45 | } @_; | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 1012 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||
| 49 | 1012 | my ($class, %args) = @_; | |||||||||||||
| 50 | 1012 | my $type = _ref(%args, '-type'); | |||||||||||||
| 51 | |||||||||||||||
| 52 | 1012 | my $self = { | |||||||||||||
| 53 | -type => $type, | ||||||||||||||
| 54 | -value => _ref(%args, '-value', ''), | ||||||||||||||
| 55 | -children => _ref(%args, '-children', []), | ||||||||||||||
| 56 | }; | ||||||||||||||
| 57 | 1012 | ▶ | croak "Unknown arguments: " . join(', ', keys %args) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | if %args; | ||||||||||||||
| 59 | 1012 | bless $self, $class; | |||||||||||||
| 60 | |||||||||||||||
| 61 | 1012 | $self->{-children} = [_flatten(@{$self->{-children}})]; | |||||||||||||
| 62 | |||||||||||||||
| 63 | 1012 | foreach my $child (@{$self->{-children}}) { | |||||||||||||
| 64 | 689 | $child->{-parent} = $self; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 1012 | foreach my $check (@{$type->{checks}}) { | |||||||||||||
| 68 | 1601 | &$check($self); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 1012 | foreach my $action (@{$type->{actions}}) { | |||||||||||||
| 72 | 30 | &$action($self); | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 1012 | DBG("Instantiated $type"); | |||||||||||||
| 76 | 1012 | $self; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 591 | ▶ | sub get { | ||||||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 80 | 591 | my ($self, $path) = @_; | |||||||||||||
| 81 | 591 | $path = Config::Maker::Path->make($path); | |||||||||||||
| 82 | 591 | my $res = $path->find($self); | |||||||||||||
| 83 | 591 | ▶ | return wantarray ? @$res : $res->[0]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | 192 | ▶ | sub get1 { | ||||||||||||
|
Subroutine
get1: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 87 | 192 | my ($self, $path) = @_; | |||||||||||||
| 88 | 192 | $path = Config::Maker::Path->make($path); | |||||||||||||
| 89 | 192 | my $res = $path->find($self); | |||||||||||||
| 90 | 192 | ▶ | Carp::croak "$path should have exactly one result" if $#$res; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 192 | return $res->[0]; | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 135 | ▶ | sub getval { | ||||||||||||
|
Subroutine
getval: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 95 | 135 | my ($self, $path, $default) = @_; | |||||||||||||
| 96 | 135 | $path = Config::Maker::Path->make($path); | |||||||||||||
| 97 | 135 | my $res = $path->find($self); | |||||||||||||
| 98 | 135 | ▶ | Carp::croak "$path should have at most one result" if @$res > 1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | 135 | ▶ | @$res ? $res->[0]->{-value} : $default; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | 0 | ▶ | sub type { | ||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 103 | 0 | $_[0]->{-type}; | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | |||||||||||||||
| 106 | 0 | ▶ | sub id { | ||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 107 | 0 | "$_[0]->{-type}:$_[0]->{-value}"; | |||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | 9 | 1; | |||||||||||||
| 111 | |||||||||||||||
| 112 | __END__ | ||||||||||||||