| 1 | package Parse::Method::Signatures::Sig; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use MooseX::Types::Moose qw/HashRef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Parse::Method::Signatures::Types qw/Param ParamCollection NamedParam/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use List::MoreUtils qw/part/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | has invocant => ( | |||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||
| 12 | does => Param, | ||||||||||||||||||||||||||||
| 13 | predicate => 'has_invocant', | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | has _positional_params => ( | |||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | isa => ParamCollection, | ||||||||||||||||||||||||||||
| 19 | init_arg => 'positional_params', | ||||||||||||||||||||||||||||
| 20 | predicate => 'has_positional_params', | ||||||||||||||||||||||||||||
| 21 | coerce => 1, | ||||||||||||||||||||||||||||
| 22 | handles => { | ||||||||||||||||||||||||||||
| 23 | positional_params => 'params', | ||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | has _named_params => ( | |||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | isa => ParamCollection, | ||||||||||||||||||||||||||||
| 30 | init_arg => 'named_params', | ||||||||||||||||||||||||||||
| 31 | predicate => 'has_named_params', | ||||||||||||||||||||||||||||
| 32 | coerce => 1, | ||||||||||||||||||||||||||||
| 33 | handles => { | ||||||||||||||||||||||||||||
| 34 | named_params => 'params', | ||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 3 | has _named_map => ( | |||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||
| 40 | isa => HashRef[Param], | ||||||||||||||||||||||||||||
| 41 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | override BUILDARGS => sub { | ||||||||||||||||||||||||||||
| 45 | 87 | ▶ | my $args = super(); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 87 | ▶ | if (my $params = delete $args->{params}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 87 | ▶ | my ($positional, $named) = part { NamedParam->check($_) ? 1 : 0 } @{ $params }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 87 | ▶ | $args->{positional_params} = $positional if $positional; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 87 | ▶ | $args->{named_params} = $named if $named; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 87 | return $args; | |||||||||||||||||||||||||||
| 54 | 3 | }; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub _build__named_map { | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build__named_map: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return {} unless $self->has_named_params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | return { map { $_->label => $_ } @{ $self->named_params } }; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub named_param { | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
named_param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | return $self->_named_map->{$name}; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | around has_positional_params => sub { | ||||||||||||||||||||||||||||
| 68 | 174 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 69 | 174 | my $ret = $orig->(@_); | |||||||||||||||||||||||||||
| 70 | 174 | ▶ | return unless $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 130 | my ($self) = @_; | |||||||||||||||||||||||||||
| 73 | 130 | return scalar @{ $self->positional_params }; | |||||||||||||||||||||||||||
| 74 | 3 | }; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | around has_named_params => sub { | ||||||||||||||||||||||||||||
| 77 | 150 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 78 | 150 | my $ret = $orig->(@_); | |||||||||||||||||||||||||||
| 79 | 150 | ▶ | return unless $ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 37 | my ($self) = @_; | |||||||||||||||||||||||||||
| 82 | 37 | return scalar @{ $self->named_params }; | |||||||||||||||||||||||||||
| 83 | 3 | }; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub to_string { | ||||||||||||||||||||||||||||
| 86 | 82 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 82 | my $ret = q{(}; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 82 | ▶ | if ($self->has_invocant) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 7 | $ret .= $self->invocant->to_string; | |||||||||||||||||||||||||||
| 91 | 7 | $ret .= q{:}; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 7 | ▶ | if ($self->has_positional_params || $self->has_named_params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_positional_params or $self->has_named_params
MC/DC100%2/2
$self->has_positional_params or $self->has_named_params
$self->has_positional_params
$self->has_named_params
Truth table100%3/3
A or B
A= $self->has_positional_paramsB= $self->has_named_params
| |||||||||||||||||||||||||||||
| 94 | 6 | $ret .= q{ }; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 82 | ▶ | $ret .= $self->_positional_params->to_string if $self->has_positional_params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 82 | ▶ | $ret .= q{, } if $self->has_positional_params && $self->has_named_params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_positional_params and $self->has_named_params
MC/DC100%2/2
$self->has_positional_params and $self->has_named_params
$self->has_positional_params
$self->has_named_params
Truth table100%3/3
A and B
A= $self->has_positional_paramsB= $self->has_named_params
| |||||||||||||||||||||||||||||
| 100 | 82 | ▶ | $ret .= $self->_named_params->to_string if $self->has_named_params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 82 | $ret .= q{)}; | |||||||||||||||||||||||||||
| 103 | 82 | return $ret; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 3 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 NAME | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | Parse::Method::Signatures::Sig - Method Signature | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Represents the parsed method signature. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head2 invocant | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head2 named_params | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | A ParamCollection representing the name parameters of this signature. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head2 positional_params | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | A ParamCollection representing the positional parameters of this signature. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 METHODS | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head2 has_named_params | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Predicate returning true if this signature has named parameters. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 has_positional_params | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Predicate returning true if this signature has positional parameters. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head2 named_param | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | Returns the Param with the specified name. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head2 to_string | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Returns a string representation of this signature. | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||