MooX-Failover

 view release on metacpan or  search on metacpan

t/12-args.t  view on Meta::CPAN

{
    package Failover2;

    use Moo;
    use Types::Standard qw/ Str ArrayRef /;

    has 'error2' => ( is => 'ro' );
    has 'class2' => ( is => 'ro', isa => Str );

    has 'num'  => ( is => 'ro' ); # can be anything

    has 'args' => ( is => 'ro', isa => ArrayRef );

    our $count = 0;

    sub alt_new {
      ++$count;
      shift->new(@_);
    }
}

{

    package Sub1;

    use Moo;
    use Types::Standard qw/ Int Str /;

    use MooX::Failover;
    use lib 't/lib';

    has num => (
        is  => 'ro',
        isa => Int,
    );

    has r_str => (
        is       => 'ro',
        isa      => Str,
        required => 1,
    );

    has d_str => (
        is       => 'ro',
        isa      => Str,
        required => 1,
        default  => sub { 'wibble' },
    );

    failover_to 'Failover2' => ( err_arg => 'error2', class_arg => 'class2', constructor => 'alt_new' , args => [  map { "'$_'" } ( num => 1234 ) ], );

    sub other {
      die "bad constructor";
    }

    failover_to 'Failover2' => (
                                err_arg => 'error2', class_arg => 'class2', constructor => 'alt_new',
      from_constructor => 'other',
      args => [ ],
      orig_arg => 'args',
    );

}

{

    package Sub2;

    use Moo;
    use Types::Standard qw/ Int Str /;

    use MooX::Failover;



( run in 1.977 second using v1.01-cache-2.11-cpan-99c4e6809bf )