The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::CoercePerAttribute - Define Coercions per attribute!

VERSION

Version 0.802

DESCRIPTION

A simple Moose Trait to allow you to define coercions per attribute.

SYNOPSIS

This module allows for coercions to be declasred on a per attribute bases. Accepting either an array of Code refs of the coercion to be run or an HashRef of various arguments to create a coearcion routine from .

    use MooseX::CoercePerAttribute;

    has foo => (isa => 'Str', is => 'ro', coerce => 1);
    has bar => (
        traits  => [CoercePerAttribute],
        isa     => Bar,
        is      => 'ro',
        coerce  => {
            Str => sub {
                my ($value, $options);
                ...
                },
            Int => sub {
                my ($value, $options);
                ...
                },
            },
        );

    use Moose::Util::Types;

    has baz => (
        traits  => [CoercePerAttribute],
        isa     => Baz,
        is      => 'ro',
        coerce  => [
            sub {
                coerce $_[0], from Str, via {}
                }]
            );

USAGE

This trait allows you to declare a type coercion inline for an attribute. The Role will create an __ANON__ sub TypeConstraint object of the TypeConstraint in the attributes isa parameter. The type coercion can be supplied in one of two methods. The coercion should be supplied to the Moose Attribute coerce parameter.

1. The recomended usage is to supply a hashref declaring the type to coerce from and a subref to be excuted. coerce => {$Fromtype => sub {}}

2. Alternatively you can supply and arrayref of coercion coderefs. These should be in the same format as defined in Moose::Util::TypeConstraints and will be passed the __ANON__ subtype as its first argument. If you use this method then you will need to use Moose::Util::TypeConstraints in you module. coerce => [sub {coerce $_[0], from Str, via sub {} }]

AUTHOR

mrf, <mrf at cpan.org>

BUGS

Please report any bugs or feature requests to bug-moosex-coerceperattribute at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-CoercePerAttribute. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc MooseX::CoercePerAttribute

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2012 mrf.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.