MooseX-CoercePerAttribute

 view release on metacpan or  search on metacpan

t/01-standard_coercion.t  view on Meta::CPAN

        return {$_ => 4};
        };

coerce 'TestStr', from 'ArrayRef',
    via {
        return shift @{$_};
        };

has test_str_coerce         => (is => 'ro', isa => 'TestStr',                   coerce => 1);
has test_int_coerce         => (is => 'ro', isa => 'TestInt',                   coerce => 1);
has test_arrayref_coerce    => (is => 'ro', isa => 'TestClass::TestArrayRef',   coerce => 1);
has test_hashref_coerce     => (is => 'ro', isa => 'TestClass::TestHashRef',    coerce => 1);
has test_str_from_array_coerce => (is => 'ro', isa => 'TestStr', coerce => 1);

STR_COERCION: {
    my $test;
    eval { $test = __PACKAGE__->new( test_str_coerce => '1') };

    ok(!$@, 'Created TestClass object without errors') || fail(Dumper($@));
    is($test->test_str_coerce => '1', 'Coercion worked correctly');
    }



( run in 0.681 second using v1.01-cache-2.11-cpan-5f2e87ce722 )