GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MOOSEX::ONEARGNEW (3)

.ds Aq ’

NAME

MooseX::OneArgNew - teach ->new to accept single, non-hashref arguments

CONTENTS

VERSION

version 0.005

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 three 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.
coerce If true, a single argument to new will be coerced into the expected type if possible. Keep in mind that if there are no coercions for the type, this will be an error, and that if a coercion from HashRef exists, you might be getting yourself into a weird situation.

    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 <B>very bad ideaB> to supply a type that could accept a normal hashref of arguments to new.

AUTHOR

Ricardo Signes <rjbs@cpan.org>

CONTRIBUTORS

o George Hartzell <hartzell@alerce.com>
o William Orr <will@worrbase.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 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.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MOOSEX::ONEARGNEW (3) 2015-07-15

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.