| 1 | package Parse::Method::Signatures::Param; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use MooseX::Types::Structured qw/Tuple/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use MooseX::Types::Moose qw/Bool Str ArrayRef HashRef/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | with 'MooseX::Traits'; | |||||||||
| 10 | |||||||||||
| 11 | 3 | has required => ( | |||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | isa => Bool, | ||||||||||
| 14 | required => 1 | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 3 | has sigil => ( | |||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | isa => Str, | ||||||||||
| 20 | required => 1, | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | 3 | has type_constraints => ( | |||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | isa => 'Parse::Method::Signatures::TypeConstraint', | ||||||||||
| 26 | predicate => 'has_type_constraints', | ||||||||||
| 27 | handles => { | ||||||||||
| 28 | meta_type_constraint => 'tc' | ||||||||||
| 29 | }, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 3 | has default_value => ( | |||||||||
| 33 | is => 'ro', | ||||||||||
| 34 | isa => Str, | ||||||||||
| 35 | predicate => 'has_default_value', | ||||||||||
| 36 | ); | ||||||||||
| 37 | |||||||||||
| 38 | 3 | has constraints => ( | |||||||||
| 39 | is => 'ro', | ||||||||||
| 40 | isa => ArrayRef[Str], | ||||||||||
| 41 | predicate => 'has_constraints', | ||||||||||
| 42 | auto_deref => 1, | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 3 | has param_traits => ( | |||||||||
| 46 | is => 'ro', | ||||||||||
| 47 | isa => ArrayRef[Tuple[Str, Str]], | ||||||||||
| 48 | predicate => 'has_traits', | ||||||||||
| 49 | auto_deref => 1 | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 3 | has '+_trait_namespace' => ( | |||||||||
| 53 | default => 'Parse::Method::Signatures::Param', | ||||||||||
| 54 | ); | ||||||||||
| 55 | |||||||||||
| 56 | sub _stringify_type_constraints { | ||||||||||
| 57 | 157 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_stringify_type_constraints: called CC=2 SCAR=6.9
| |||||||||||
| 58 | 157 | ▶ | return $self->has_type_constraints | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | ? $self->type_constraints->to_string . q{ } | ||||||||||
| 60 | : q{}; | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | sub _stringify_default_value { | ||||||||||
| 64 | 157 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_stringify_default_value: called CC=2 SCAR=6.9
| |||||||||||
| 65 | 157 | ▶ | return $self->has_default_value | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | ? q{ = } . $self->default_value | ||||||||||
| 67 | : q{}; | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | sub _stringify_constraints { | ||||||||||
| 71 | 157 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_stringify_constraints: called CC=2 SCAR=6.9
| |||||||||||
| 72 | 157 | ▶ | return q{} unless $self->has_constraints; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 7 | return q{ where } . join(q{ where }, $self->constraints); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub _stringify_traits { | ||||||||||
| 77 | 157 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_stringify_traits: called CC=2 SCAR=6.9
| |||||||||||
| 78 | 157 | ▶ | return q{} unless $self->has_traits; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 5 | return q{ } . join q{ }, map { @{ $_ } } $self->param_traits; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | sub to_string { | ||||||||||
| 83 | 157 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 84 | 157 | my $ret = q{}; | |||||||||
| 85 | |||||||||||
| 86 | 157 | $ret .= $self->_stringify_type_constraints; | |||||||||
| 87 | 157 | $ret .= $self->_stringify_variable_name; | |||||||||
| 88 | 157 | $ret .= $self->_stringify_required; | |||||||||
| 89 | 157 | $ret .= $self->_stringify_default_value; | |||||||||
| 90 | 157 | $ret .= $self->_stringify_constraints; | |||||||||
| 91 | 157 | $ret .= $self->_stringify_traits; | |||||||||
| 92 | |||||||||||
| 93 | 157 | return $ret; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||
| 97 | |||||||||||
| 98 | 3 | 1; | |||||||||
| 99 | |||||||||||
| 100 | =head1 NAME | ||||||||||
| 101 | |||||||||||
| 102 | Parse::Method::Signatures::Param - a parsed parameter from a signature | ||||||||||
| 103 | |||||||||||
| 104 | =head1 ATTRIBUTES | ||||||||||
| 105 | |||||||||||
| 106 | All attributes of this class are read-only. | ||||||||||
| 107 | |||||||||||
| 108 | =head2 required | ||||||||||
| 109 | |||||||||||
| 110 | Is this parameter required (true) or optional (false)? | ||||||||||
| 111 | |||||||||||
| 112 | =head2 sigil | ||||||||||
| 113 | |||||||||||
| 114 | The effective sigil ('$', '@' or '%') of this parameter. | ||||||||||
| 115 | |||||||||||
| 116 | =head2 type_constraints | ||||||||||
| 117 | |||||||||||
| 118 | =over | ||||||||||
| 119 | |||||||||||
| 120 | B<Type:> L<Parse::Method::Signatures::TypeConstraint> | ||||||||||
| 121 | |||||||||||
| 122 | B<Predicate:> has_type_constraints | ||||||||||
| 123 | |||||||||||
| 124 | =back | ||||||||||
| 125 | |||||||||||
| 126 | Representation of the type constraint for this parameter. Most commonly you | ||||||||||
| 127 | will just call L</meta_type_constraint> and not access this attribute directly. | ||||||||||
| 128 | |||||||||||
| 129 | =head2 default_value | ||||||||||
| 130 | |||||||||||
| 131 | =over | ||||||||||
| 132 | |||||||||||
| 133 | B<Type:> Str | ||||||||||
| 134 | |||||||||||
| 135 | B<Predicate:> has_default_value | ||||||||||
| 136 | |||||||||||
| 137 | =back | ||||||||||
| 138 | |||||||||||
| 139 | A string that should be eval'd or injected to get the default value for this | ||||||||||
| 140 | parameter. For example: | ||||||||||
| 141 | |||||||||||
| 142 | $name = 'bar' | ||||||||||
| 143 | |||||||||||
| 144 | Would give a default_value of "'bar'". | ||||||||||
| 145 | |||||||||||
| 146 | =head2 constraints | ||||||||||
| 147 | |||||||||||
| 148 | =over | ||||||||||
| 149 | |||||||||||
| 150 | B<Type:> ArrayRef[Str] | ||||||||||
| 151 | |||||||||||
| 152 | B<Predicate:> has_constraints | ||||||||||
| 153 | |||||||||||
| 154 | =back | ||||||||||
| 155 | |||||||||||
| 156 | C<where> constraints for this type. Each member of the array a the string | ||||||||||
| 157 | (including enclosing braces) of the where constraint block. | ||||||||||
| 158 | |||||||||||
| 159 | =head2 param_traits | ||||||||||
| 160 | |||||||||||
| 161 | =over | ||||||||||
| 162 | |||||||||||
| 163 | B<Type:> ArrayRef[ Tupple[Str,Str] ] | ||||||||||
| 164 | |||||||||||
| 165 | B<Predicate:> has_traits | ||||||||||
| 166 | |||||||||||
| 167 | =back | ||||||||||
| 168 | |||||||||||
| 169 | Traits that this parameter is declared to have. For instance | ||||||||||
| 170 | |||||||||||
| 171 | $foo does coerce | ||||||||||
| 172 | |||||||||||
| 173 | would have a trait of | ||||||||||
| 174 | |||||||||||
| 175 | ['does', 'coerce'] | ||||||||||
| 176 | |||||||||||
| 177 | =head1 METHODS | ||||||||||
| 178 | |||||||||||
| 179 | =head2 to_string | ||||||||||
| 180 | |||||||||||
| 181 | =head2 meta_type_constraint | ||||||||||
| 182 | |||||||||||
| 183 | Get the L<Moose::Meta::TypeConstraint> for this parameter. Check first that the | ||||||||||
| 184 | type has a type constraint: | ||||||||||
| 185 | |||||||||||
| 186 | $tc = $param->meta_type_constraint if $param->has_type_constraints; | ||||||||||
| 187 | |||||||||||
| 188 | =head1 SEE ALSO | ||||||||||
| 189 | |||||||||||
| 190 | L<Parse::Method::Signatures>. | ||||||||||
| 191 | |||||||||||
| 192 | =head1 AUTHORS | ||||||||||
| 193 | |||||||||||
| 194 | Ash Berlin <ash@cpan.org>. | ||||||||||
| 195 | |||||||||||
| 196 | Florian Ragwitz <rafl@debian.org>. | ||||||||||
| 197 | |||||||||||
| 198 | =head1 LICENSE | ||||||||||
| 199 | |||||||||||
| 200 | Licensed under the same terms as Perl itself. | ||||||||||
| 201 | |||||||||||