1 package Parse::Method::Signatures::Param;
4 use MooseX::Types::Structured qw/Tuple/;
5 use MooseX::Types::Moose qw/Bool Str ArrayRef HashRef/;
7 use namespace::clean -except => 'meta';
23 has type_constraints => (
25 isa => 'Parse::Method::Signatures::TypeConstraint',
26 predicate => 'has_type_constraints',
28 meta_type_constraint => 'tc'
32 has default_value => (
35 predicate => 'has_default_value',
41 predicate => 'has_constraints',
47 isa => ArrayRef[Tuple[Str, Str]],
48 predicate => 'has_traits',
52 has '+_trait_namespace' => (
53 default => 'Parse::Method::Signatures::Param',
56 sub _stringify_type_constraints {
58 return $self->has_type_constraints
59 ? $self->type_constraints->to_string . q{ }
63 sub _stringify_default_value {
65 return $self->has_default_value
66 ? q{ = } . $self->default_value
70 sub _stringify_constraints {
72 return q{} unless $self->has_constraints;
73 return q{ where } . join(q{ where }, $self->constraints);
76 sub _stringify_traits {
78 return q{} unless $self->has_traits;
79 return q{ } . join q{ }, map { @{ $_ } } $self->param_traits;
86 $ret .= $self->_stringify_type_constraints;
87 $ret .= $self->_stringify_variable_name;
88 $ret .= $self->_stringify_required;
89 $ret .= $self->_stringify_default_value;
90 $ret .= $self->_stringify_constraints;
91 $ret .= $self->_stringify_traits;
96 __PACKAGE__->meta->make_immutable;
102 Parse::Method::Signatures::Param - a parsed parameter from a signature
106 All attributes of this class are read-only.
110 Is this parameter required (true) or optional (false)?
114 The effective sigil ('$', '@' or '%') of this parameter.
116 =head2 type_constraints
120 B<Type:> L<Parse::Method::Signatures::TypeConstraint>
122 B<Predicate:> has_type_constraints
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.
135 B<Predicate:> has_default_value
139 A string that should be eval'd or injected to get the default value for this
140 parameter. For example:
144 Would give a default_value of "'bar'".
150 B<Type:> ArrayRef[Str]
152 B<Predicate:> has_constraints
156 C<where> constraints for this type. Each member of the array a the string
157 (including enclosing braces) of the where constraint block.
163 B<Type:> ArrayRef[ Tupple[Str,Str] ]
165 B<Predicate:> has_traits
169 Traits that this parameter is declared to have. For instance
173 would have a trait of
181 =head2 meta_type_constraint
183 Get the L<Moose::Meta::TypeConstraint> for this parameter. Check first that the
184 type has a type constraint:
186 $tc = $param->meta_type_constraint if $param->has_type_constraints;
190 L<Parse::Method::Signatures>.
194 Ash Berlin <ash@cpan.org>.
196 Florian Ragwitz <rafl@debian.org>.
200 Licensed under the same terms as Perl itself.