| 1 | package Smart::Dispatch::Match; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 5 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||
| 4 | *_TYPES = $ENV{PERL_SMART_DISPATCH_TYPE_CHECKS}==42 | ||||||||||||||
| 5 | ? sub () { 1 } | ||||||||||||||
| 6 | 5 | ▶ | : sub () { 0 }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 7 | }; | ||||||||||||||
| 8 | |||||||||||||||
| 9 | 5 | ▶ | use 5.010; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 5 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 5 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 5 | ▶ | use if _TYPES, 'MooX::Types::MooseLike::Base', ':all'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 5 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 5 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 5 | $Smart::Dispatch::Match::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||
| 18 | 5 | $Smart::Dispatch::Match::VERSION = '0.006'; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 5 | ▶ | use constant { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 5 | FLAG_HAS_VALUE => 2, | |||||||||||||
| 23 | FLAG_HAS_DISPATCH => 4, | ||||||||||||||
| 24 | FLAG_IS_FAILOVER => 8, | ||||||||||||||
| 25 | FLAG_IS_UNCONDITIONAL => 16, | ||||||||||||||
| 26 | 5 | }; | |||||||||||||
| 27 | |||||||||||||||
| 28 | use overload | ||||||||||||||
| 29 | 2 | ▶ | '&{}' => sub { my $x=shift; sub { $x->conduct_dispatch($_[0]) } }, | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 30 | '~~' => 'value_matches', | ||||||||||||||
| 31 | 11 | ▶ | bool => sub { 1 }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 32 | 5 | ; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 5 | has test => ( | |||||||||||||
| 35 | (_TYPES?(isa=>Any()):()), | ||||||||||||||
| 36 | is => 'ro', | ||||||||||||||
| 37 | required => 1, | ||||||||||||||
| 38 | ); | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 5 | has dispatch => ( | |||||||||||||
| 41 | (_TYPES?(isa=>CodeRef()):()), | ||||||||||||||
| 42 | is => 'ro', | ||||||||||||||
| 43 | required => 0, | ||||||||||||||
| 44 | predicate => 'has_dispatch', | ||||||||||||||
| 45 | ); | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 5 | has value => ( | |||||||||||||
| 48 | (_TYPES?(isa=>Any()):()), | ||||||||||||||
| 49 | is => 'ro', | ||||||||||||||
| 50 | required => 0, | ||||||||||||||
| 51 | predicate => 'has_value', | ||||||||||||||
| 52 | ); | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 5 | has note => ( | |||||||||||||
| 55 | (_TYPES?(isa=>Str()):()), | ||||||||||||||
| 56 | is => 'ro', | ||||||||||||||
| 57 | required => 0, | ||||||||||||||
| 58 | ); | ||||||||||||||
| 59 | |||||||||||||||
| 60 | 5 | has bitflags => ( | |||||||||||||
| 61 | (_TYPES?(isa=>Num()):()), | ||||||||||||||
| 62 | is => 'lazy', | ||||||||||||||
| 63 | init_arg => undef, | ||||||||||||||
| 64 | ); | ||||||||||||||
| 65 | |||||||||||||||
| 66 | has is_failover => ( | ||||||||||||||
| 67 | (_TYPES?(isa=>Bool()):()), | ||||||||||||||
| 68 | is => 'ro', | ||||||||||||||
| 69 | required => 1, | ||||||||||||||
| 70 | 16 | ▶ | default => sub { 0 }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 71 | 5 | ); | |||||||||||||
| 72 | |||||||||||||||
| 73 | has is_unconditional => ( | ||||||||||||||
| 74 | (_TYPES?(isa=>Bool()):()), | ||||||||||||||
| 75 | is => 'ro', | ||||||||||||||
| 76 | required => 1, | ||||||||||||||
| 77 | 18 | ▶ | default => sub { 0 }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 78 | 5 | ); | |||||||||||||
| 79 | |||||||||||||||
| 80 | sub _build_bitflags | ||||||||||||||
| 81 | 0 | ▶ | { | ||||||||||||
|
Subroutine
_build_bitflags: not called CC=5 SCAR=34.0
| |||||||||||||||
| 82 | 0 | my ($self) = @_; | |||||||||||||
| 83 | 0 | my $rv = 1; | |||||||||||||
| 84 | 0 | ▶ | $rv += FLAG_HAS_VALUE if $self->has_value; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | 0 | ▶ | $rv += FLAG_HAS_DISPATCH if $self->has_dispatch; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | 0 | ▶ | $rv += FLAG_IS_FAILOVER if $self->is_failover; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | 0 | ▶ | $rv += FLAG_IS_UNCONDITIONAL if $self->is_unconditional; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 88 | 0 | return $rv; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | sub value_matches | ||||||||||||||
| 92 | 66 | ▶ | { | ||||||||||||
|
Subroutine
value_matches: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 93 | 66 | my ($self, $value) = @_; | |||||||||||||
| 94 | 66 | local $_ = $value; | |||||||||||||
| 95 | 5 | ▶ | no warnings; # stupid useless warnings below | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 96 | 66 | return ($value ~~ $self->test); | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | |||||||||||||||
| 99 | sub conduct_dispatch | ||||||||||||||
| 100 | 13 | ▶ | { | ||||||||||||
|
Subroutine
conduct_dispatch: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||
| 101 | 13 | my ($self, $value, @args) = @_; | |||||||||||||
| 102 | 13 | local $_ = $value; | |||||||||||||
| 103 | 13 | ▶ | if ($self->has_dispatch) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 104 | { | ||||||||||||||
| 105 | 11 | return $self->dispatch->($value, @args); | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | elsif ($self->has_value) | ||||||||||||||
| 108 | { | ||||||||||||||
| 109 | 2 | return $self->value; | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | else | ||||||||||||||
| 112 | { | ||||||||||||||
| 113 | 0 | return; | |||||||||||||
| 114 | } | ||||||||||||||
| 115 | } | ||||||||||||||
| 116 | |||||||||||||||
| 117 | 5 | __PACKAGE__ | |||||||||||||
| 118 | __END__ | ||||||||||||||