/usr/share/perl5/MooseX/Types/UndefinedType.pm is in libmoosex-types-perl 0.31-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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | package MooseX::Types::UndefinedType;
{
$MooseX::Types::UndefinedType::VERSION = '0.31';
}
use warnings;
use strict;
use Moose::Util::TypeConstraints ();
use Carp::Clan qw( ^MooseX::Types );
use overload '""' => sub { shift->name },
fallback => 1;
=head1 NAME
MooseX::Types::UndefinedType - Represents a not yet defined type
=head1 DESCRIPTION
Whenever a type handle function (e.g. C<Int()> can't find a type
constraint under it's full name, it assumes it has not yet been defined.
It will then return an instance of this class, handling only
stringification, name and possible identification of undefined types.
Later, when you try to use the Undefined Type Constraint, autovivification will
be attempted.
=head1 METHODS
=head2 new
Takes a full type name as argument and returns an instance of this
class.
=cut
sub new {
return bless { name => $_[1] }, $_[0];
}
=head2 name
Returns the stored type name.
=cut
sub name {
return $_[0]->{name};
}
=head2 __autovivify
Try to see if the type constraint has yet been defined and if so create it.
=cut
sub __autovivify {
my ($self) = @_;
if(my $tc = $self->{instance}) {
return $tc;
} elsif( my $new_tc = Moose::Util::TypeConstraints::find_type_constraint($self->name)) {
$self->{instance} = $new_tc;
return $new_tc;
} else {
return;
}
}
=head2 can_be_inlined
Make sure that if a type hasn't been defined yet when Moose wants to inline it,
we don't allow inlining.
=cut
sub can_be_inlined {
my $self = shift;
if(my $type_constraint = $self->__autovivify) {
return $type_constraint->can_be_inlined;
} else {
return;
}
}
=head2 AUTOLOAD
Try to autovivify and delegate
=cut
sub AUTOLOAD {
my ($self, @args) = @_;
my ($method) = our $AUTOLOAD =~ /([^:]+)$/;
if(my $type_constraint = $self->__autovivify) {
return $type_constraint->$method(@args);
} else {
croak "Method '$method' is not supported for " . $self->name;
}
}
=head2 DESTROY
Moose::Meta::TypeConstraint::Parameterizable complains if this isn't here. TODO
to find out why.
=cut
sub DESTROY {
return;
}
=head1 SEE ALSO
L<MooseX::Types::Moose>,
L<Moose::Util::TypeConstraints>,
L<Moose::Meta::TypeConstraint>,
L<Carp::Clan>
=head1 LICENSE
This program is free software; you can redistribute it and/or modify
it under the same terms as perl itself.
=cut
1;
|