/usr/share/perl5/MooseX/UndefTolerant/Attribute.pm is in libmoosex-undeftolerant-perl 0.20-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | package MooseX::UndefTolerant::Attribute;
our $VERSION = '0.20';
use Moose::Role;
use namespace::autoclean;
around('initialize_instance_slot', sub {
my $orig = shift;
my $self = shift;
my ($meta_instance, $instance, $params) = @_;
my $key_name = $self->init_arg;
# If our parameter passed in was undef, remove it from the parameter list...
# but leave the value unscathed if the attribute's type constraint can
# handle undef (or doesn't have one, which implicitly means it can)
if (defined $key_name and not defined($params->{$key_name}))
{
my $type_constraint = $self->type_constraint;
if ($type_constraint and not $type_constraint->check(undef))
{
delete $params->{$key_name};
}
}
# Invoke the real init, as the above line cleared the undef param value
$self->$orig(@_)
});
1;
# ABSTRACT: Make your attribute(s) tolerant to undef initialization
__END__
=pod
=encoding UTF-8
=head1 NAME
MooseX::UndefTolerant::Attribute - Make your attribute(s) tolerant to undef initialization
=head1 VERSION
version 0.20
=head1 SYNOPSIS
package My:Class;
use Moose;
use MooseX::UndefTolerant::Attribute;
has 'bar' => (
traits => [ qw(MooseX::UndefTolerant::Attribute)],
is => 'ro',
isa => 'Num',
predicate => 'has_bar'
);
# Meanwhile, under the city...
# Doesn't explode
my $class = My::Class->new(bar => undef);
$class->has_bar # False!
=head1 DESCRIPTION
Applying this trait to your attribute makes it's initialization tolerant of
of undef. If you specify the value of undef to any of the attributes they
will not be initialized (or will be set to the default, if applicable).
Effectively behaving as if you had not provided a value at all.
=head1 AUTHOR
Cory G Watson <gphat at cpan.org>
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2011 by Cory G Watson.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|