| MooseX-Method documentation | Contained in the MooseX-Method distribution. |
MooseX::Meta::Signature::Combined - Combined signature metaclass
This API is unstable, it may change at any time. This should not affect ordinary MooseX::Method usage.
use MooseX::Meta::Signature::Combined;
my $signature = MooseX::Meta::Signature::Combined->new (
{ isa => 'Int' },
foo => { required => 1 },
);
my @results;
eval {
@results = $signature->validate (23,bar => 2);
};
Validates the arguments against the signature. The first arguments must be the positional ones. The named arguments must be in the form of a hash, unlike the named signature this does not support hashrefs. Returns a list of the validated positional arguments and a hashref of the validated named arguments or throws an exception on validation error.
Returns the named signature.
Returns the positional signature.
Returns the length of the positional signature.
Most software has bugs. This module probably isn't an exception. If you find a bug please either email me, or add the bug to cpan-RT.
Anders Nor Berle <debolaz@gmail.com>
Copyright 2007 by Anders Nor Berle.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| MooseX-Method documentation | Contained in the MooseX-Method distribution. |
package MooseX::Meta::Signature::Combined; use Moose; use MooseX::Meta::Signature::Named; use MooseX::Meta::Signature::Positional; has named_signature => (is => 'ro',isa => 'MooseX::Meta::Signature::Named'); has positional_signature => (is => 'ro',isa => 'MooseX::Meta::Signature::Positional'); has positional_signature_size => (is => 'ro',isa => 'Int'); with qw/MooseX::Meta::Signature/; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:BERLE'; sub _positional_metaclass { 'MooseX::Meta::Signature::Positional' } sub _named_metaclass { 'MooseX::Meta::Signature::Named' } sub new { my ($class,@parameters) = @_; my $self = $class->meta->new_object; my @positional_params; my %named_params; while (my $param = shift @parameters) { if (ref $param) { $param->{required} = 1 if ref $param eq 'HASH'; push @positional_params,$param; } else { $named_params{$param} = shift @parameters; } } $self->{named_signature} = $self->_named_metaclass->new (%named_params); $self->{positional_signature} = $self->_positional_metaclass->new (@positional_params); $self->{positional_signature_size} = scalar @positional_params; return $self; } sub validate { my ($self,@args) = @_; my @positional_args = (scalar @args <= $self->{positional_signature_size} ? @args : @args[0..($self->{positional_signature_size} - 1)]); my %named_args = @args[$self->{positional_signature_size}..$#args]; return $self->{positional_signature}->validate (@positional_args), $self->{named_signature}->validate (%named_args); } __PACKAGE__->meta->make_immutable(inline_constructor => 0); 1; __END__