<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">=head1 NAME

MooX::Failover - Instantiate Moo classes with failover

=head1 VERSION

v0.3.0

=head1 SYNOPSIS

  # In your class:

  package MyClass;

  use Moo;
  use MooX::Failover;

  has 'attr' =&gt; ( ... );

  # after attributes are defined:

  failover_to 'OtherClass';

  ...

  # When using the class

  my $obj = MyClass-&gt;new( %args );

  # If %args contains missing or invalid values or new otherwise
  # fails, then $obj will be of type "OtherClass".

=head1 INSTALLATION

See
L&lt;How to install CPAN modules|http://www.cpan.org/modules/INSTALL.html&gt;.

=head2 Required Modules

This distribution requires Perl v5.10.0.

This distribution requires the following modules:

=over 4

=item * L&lt;Class::Load&gt; (version 0.20)

=item * L&lt;Moo&gt;

=item * L&lt;Sub::Defer&gt;

=item * L&lt;Sub::Quote&gt;

=item * L&lt;Test::Most&gt;

=item * L&lt;Types::Standard&gt;

=back

This distribution recommends the following modules:

=over 4

=item * L&lt;Class::Load::XS&gt;

=back

=head1 RECENT CHANGES

=head2 Bug Fixes

=over 4

=item * 

Fixed bug with handling the "args" option.

=back

=head2 Documentation

=over 4

=item * 

Changed description of the "constructor" option to remove any confusion which class it applies to.

=item * 

Documented the need for quoting values in the "args" option.

=item * 

Fixed typos in POD.

=back

=head2 Enhancements

=over 4

=item * 

Added the ability to specify an alternative constructor name on the original class.

=item * 

Added the ability to pass all of the original arguments in a single constructor parameter to the failover class.

=back

See the F&lt;Changes&gt; file for a longer revision history.

=head1 DESCRIPTION

This module provides constructor failover for L&lt;Moo&gt; classes.

For example, if a class cannot be instantiated because of invalid arguments
(perhaps from an untrusted source), then instead it returns the
failover class (passing the same arguments to that class).

It is roughly equivalent to using

  my $obj = eval { MyClass-&gt;new(%args) //
     OtherClass-&gt;new( %args, error =&gt; $@ );

This allows for cleaner design, by not forcing you to duplicate type
checking for constructor parameters.

A use case for this module is for instantiating
L&lt;Web::Machine::Resource&gt; objects, where a resource class's attributes
correspond to URL arguments.  A type failure would normally cause an
internal serror error (HTTP 500).  Using L&lt;MooX::Failover&gt;, we can
return a different resource object that examines the error, and
returns a more appropriate error code, e.g. bad request (HTTP 400).

See the module documentation for L&lt;MooX::Failover&gt; for more information.

=head1 SEE ALSO

L&lt;MooseX::Failover&gt;

=head1 AUTHOR

Robert Rothenberg C&lt;&lt;rrwo@thermeon.com&gt;&gt;

=head1 Acknowledgements

=over

=item Thermeon.

=item Piers Cawley.

=back

=head1 COPYRIGHT

Copyright 2014 Thermeon Worldwide, PLC.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

This program is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.

</pre></body></html>