bump version to 0.26
[gitmo/MooseX-Types.git] / lib / MooseX / Types / UndefinedType.pm
CommitLineData
52d358e2 1package MooseX::Types::UndefinedType;
6a1db9c7 2our $VERSION = "0.26";
e211870f 3
4=head1 NAME
5
52d358e2 6MooseX::Types::UndefinedType - Represents a not yet defined type
e211870f 7
8=cut
9
10use warnings;
11use strict;
12
077ac262 13use Moose::Util::TypeConstraints ();
14use Carp::Clan qw( ^MooseX::Types );
15
e211870f 16use overload '""' => sub { shift->name },
17 fallback => 1;
18
19=head1 DESCRIPTION
20
21Whenever a type handle function (e.g. C<Int()> can't find a type
22constraint under it's full name, it assumes it has not yet been defined.
23It will then return an instance of this class, handling only
24stringification, name and possible identification of undefined types.
25
077ac262 26Later, when you try to use the Undefined Type Constraint, autovivification will
27be attempted.
28
e211870f 29=head1 METHODS
30
31=head2 new
32
33Takes a full type name as argument and returns an instance of this
34class.
35
36=cut
37
077ac262 38sub new {
39 return bless { name => $_[1] }, $_[0];
40}
e211870f 41
42=head2 name
43
44Returns the stored type name.
45
46=cut
47
077ac262 48sub name {
49 return $_[0]->{name};
50}
51
e512ffb3 52=head2 can_be_inlined
53
54Always returns false. Needed for compatbility with Moose 2.0100+.
55
56=cut
57
58sub can_be_inlined { 0 }
59
077ac262 60=head2 __autovivify
61
62Try to see if the type constraint has yet been defined and if so create it.
63
64=cut
65
66sub __autovivify {
67 my ($self) = @_;
68 if(my $tc = $self->{instance}) {
69 return $tc;
70 } elsif( my $new_tc = Moose::Util::TypeConstraints::find_type_constraint($self->name)) {
71 $self->{instance} = $new_tc;
72 return $new_tc;
73 } else {
74 return;
75 }
76}
77
78=head2 AUTOLOAD
79
80Try to autovivify and delegate
81
82=cut
83
84sub AUTOLOAD {
85 my ($self, @args) = @_;
86 my ($method) = our $AUTOLOAD =~ /([^:]+)$/;
87
88 if(my $type_constraint = $self->__autovivify) {
89 return $type_constraint->$method(@args);
90 } else {
91 croak "Method '$method' is not supported for " . $self->name;
92 }
93}
94
95=head2 DESTROY
96
97Moose::Meta::TypeConstraint::Parameterizable complains if this isn't here. TODO
98to find out why.
99
100=cut
101
102sub DESTROY {
103 return;
104}
e211870f 105
106=head1 SEE ALSO
107
52d358e2 108L<MooseX::Types::Moose>,
e211870f 109L<Moose::Util::TypeConstraints>,
077ac262 110L<Moose::Meta::TypeConstraint>,
111L<Carp::Clan>
e211870f 112
b55332a8 113=head1 AUTHOR
e211870f 114
b55332a8 115See L<MooseX::Types/AUTHOR>.
077ac262 116
e211870f 117=head1 LICENSE
118
119This program is free software; you can redistribute it and/or modify
120it under the same terms as perl itself.
121
122=cut
123
124
1251;