1 package MooseX::UndefTolerant::Attribute;
4 around('initialize_instance_slot', sub{
8 # If the parameter passed in was undef, quietly do nothing but return
9 return unless defined($_->[2]);
11 # If it was defined, call the real init slot method
19 MooseX::UndefTolerant::Attribute - Make your attribute tolerant to undef intitialization
26 use MooseX::UndefTolerant::Attribute;
29 traits => [ qw(MooseX::UndefTolerant::Attribute)],
32 predicate => 'has_bar'
35 # Meanwhile, under the city...
38 my $class = My::Class->new(bar => undef);
39 $class->has_bar # False!
43 Applying this trait to your attribute makes it's initialization tolerant of
44 of undef. If you specify the value of undef to any of the attributes they
45 will not be initialized. Effectively behaving as if you had not provided a
50 Cory G Watson, C<< <gphat at cpan.org> >>
52 =head1 COPYRIGHT & LICENSE
54 Copyright 2009 Cory G Watson.
56 This program is free software; you can redistribute it and/or modify it
57 under the terms of either: the GNU General Public License as published
58 by the Free Software Foundation; or the Artistic License.
60 See http://dev.perl.org/licenses/ for more information.