Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

moosex::oneargnew(3pm) [debian man page]

MooseX::OneArgNew(3pm)					User Contributed Perl Documentation				    MooseX::OneArgNew(3pm)

NAME
MooseX::OneArgNew - teach ->new to accept single, non-hashref arguments VERSION
version 0.002 SYNOPSIS
In our class definition: package Delivery; use Moose; with('MooseX::OneArgNew' => { type => 'Existing::Message::Type', init_arg => 'message', }); has message => (isa => 'Existing::Message::Type', required => 1); has to => ( is => 'ro', isa => 'Str', lazy => 1, default => sub { my ($self) = @_; $self->message->get('To'); }, ); When making a message: # The traditional way: my $delivery = Delivery->new({ message => $message }); # or my $delivery = Delivery->new({ message => $message, to => $to }); # With one-arg new: my $delivery = Delivery->new($message); DESCRIPTION
MooseX::OneArgNew lets your constructor take a single argument, which will be translated into the value for a one-entry hashref. It is a parameterized role with two parameters: type The Moose type that the single argument must be for the one-arg form to work. This should be an existing type, and may be either a string type or a MooseX::Type. init_arg This is the string that will be used as the key for the hashref constructed from the one-arg call to new. WARNINGS You can apply MooseX::OneArgNew more than once, but if more than one application's type matches a single argument to "new", the behavior is undefined and likely to cause bugs. It would be a very bad idea to supply a type that could accept a normal hashref of arguments to "new". AUTHOR
Ricardo Signes <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.12.3 2011-06-15 MooseX::OneArgNew(3pm)

Check Out this Related Man Page

MooseX::Types::Moose(3pm)				User Contributed Perl Documentation				 MooseX::Types::Moose(3pm)

NAME
MooseX::Types::Moose - Type exports that match the types shipped with Moose VERSION
version 0.35 SYNOPSIS
package Foo; use Moose; use MooseX::Types::Moose qw( ArrayRef Int Str ); use Carp qw( croak ); has 'name', is => 'rw', isa => Str; has 'ids', is => 'rw', isa => ArrayRef[Int]; sub add { my ($self, $x, $y) = @_; croak 'First arg not an Int' unless is_Int($x); croak 'Second arg not an Int' unless is_Int($y); return $x + $y; } 1; DESCRIPTION
This package contains a virtual library for MooseX::Types that is able to export all types known to Moose. See MooseX::Types for general usage information. METHODS
type_storage Overrides MooseX::Types::Base' "type_storage" to provide a hash reference containing all built-in Moose types. SEE ALSO
MooseX::Types::Moose, Moose, Moose::Util::TypeConstraints LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as perl itself. AUTHOR
Robert "phaylon" Sedlacek <rs@474.at> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Robert "phaylon" Sedlacek. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-05-19 MooseX::Types::Moose(3pm)
Man Page