1 package MooseX::UndefTolerant::Attribute;
4 around('initialize_instance_slot', sub {
8 my $ia = $self->init_arg;
10 # $_[2] is the hashref of options passed to the constructor. If our
11 # parameter passed in was undef, pop it off the args...
12 pop unless (defined $ia && defined($_[2]->{$ia}));
14 # Invoke the real init, as the above line cleared the unef
22 MooseX::UndefTolerant::Attribute - Make your attribute(s) tolerant to undef intitialization
29 use MooseX::UndefTolerant::Attribute;
32 traits => [ qw(MooseX::UndefTolerant::Attribute)],
35 predicate => 'has_bar'
38 # Meanwhile, under the city...
41 my $class = My::Class->new(bar => undef);
42 $class->has_bar # False!
46 Applying this trait to your attribute makes it's initialization tolerant of
47 of undef. If you specify the value of undef to any of the attributes they
48 will not be initialized (or will be set to the default, if applicable).
49 Effectively behaving as if you had not provided a value at all.
53 Cory G Watson, C<< <gphat at cpan.org> >>
55 =head1 COPYRIGHT & LICENSE
57 Copyright 2009 Cory G Watson.
59 This program is free software; you can redistribute it and/or modify it
60 under the terms of either: the GNU General Public License as published
61 by the Free Software Foundation; or the Artistic License.
63 See http://dev.perl.org/licenses/ for more information.