7 use warnings FATAL => 'redefine'; # to avoid to load Mouse::PurePerl
14 return 0 if ref($class) || !defined($class) || !length($class);
16 # walk the symbol table tree to avoid autovififying
17 # \*{${main::}{"Foo::"}} == \*main::Foo::
20 foreach my $part (split('::', $class)) {
21 my $entry = \$pack->{$part . '::'};
22 return 0 if ref($entry) ne 'GLOB';
23 $pack = *{$entry}{HASH} or return 0;
26 # check for $VERSION or @ISA
27 return 1 if exists $pack->{VERSION}
28 && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} };
29 return 1 if exists $pack->{ISA}
30 && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0;
32 # check for any method
33 foreach my $name( keys %{$pack} ) {
34 my $entry = \$pack->{$name};
35 return 1 if ref($entry) ne 'GLOB' || defined *{$entry}{CODE};
43 # taken from Sub::Identify
46 ref($coderef) or return;
48 my $cv = B::svref_2object($coderef);
49 $cv->isa('B::CV') or return;
52 $gv->isa('B::GV') or return;
54 return ($gv->STASH->NAME, $gv->NAME);
60 my $cv = B::svref_2object($coderef);
61 $cv->isa('B::CV') or return '';
64 $gv->isa('B::GV') or return '';
66 return $gv->STASH->NAME;
70 my($package, $name) = @_;
73 use warnings FATAL => 'uninitialized';
74 return *{$package . '::' . $name}{CODE};
78 Mouse::Util::TypeConstraints;
80 use Scalar::Util qw(blessed looks_like_number openhandle);
82 sub _generate_class_type_for{
83 my($for_class, $name) = @_;
85 my $predicate = sub{ blessed($_[0]) && $_[0]->isa($for_class) };
89 *{ caller() . '::' . $name } = $predicate;
100 sub Bool { $_[0] ? $_[0] eq '1' : 1 }
101 sub Undef { !defined($_[0]) }
102 sub Defined { defined($_[0]) }
103 sub Value { defined($_[0]) && !ref($_[0]) }
104 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
105 sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
106 sub Str { defined($_[0]) && !ref($_[0]) }
108 sub Ref { ref($_[0]) }
109 sub ScalarRef { ref($_[0]) eq 'SCALAR' }
110 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
111 sub HashRef { ref($_[0]) eq 'HASH' }
112 sub CodeRef { ref($_[0]) eq 'CODE' }
113 sub RegexpRef { ref($_[0]) eq 'Regexp' }
114 sub GlobRef { ref($_[0]) eq 'GLOB' }
117 openhandle($_[0]) || (blessed($_[0]) && $_[0]->isa("IO::Handle"))
120 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
122 sub ClassName { Mouse::Util::is_class_loaded($_[0]) }
123 sub RoleName { (Mouse::Util::class_of($_[0]) || return 0)->isa('Mouse::Meta::Role') }
129 sub name { $_[0]->{package} }
131 sub _method_map { $_[0]->{methods} }
132 sub _attribute_map{ $_[0]->{attribute_map} }
135 my $name = $_[0]->{package};
137 return \%{ $name . '::' };
141 my($self, $name, $code) = @_;
144 $self->throw_error('You must pass a defined name');
147 $self->throw_error('You must pass a defined code');
150 if(ref($code) ne 'CODE'){
151 $code = \&{$code}; # coerce
154 $self->{methods}->{$name} = $code; # Moose stores meta object here.
156 my $pkg = $self->name;
158 no warnings 'redefine', 'once';
159 *{ $pkg . '::' . $name } = $code;
168 return exists $_[0]->{anon_serial_id};
171 sub roles { $_[0]->{roles} }
173 sub linearized_isa { @{ get_linear_isa($_[0]->{package}) } }
179 return exists $_[0]->{anon_serial_id};
182 sub get_roles { $_[0]->{roles} }
185 Mouse::Meta::Attribute;
187 use Mouse::Meta::Method::Accessor;
191 sub name { $_[0]->{name} }
192 sub associated_class { $_[0]->{associated_class} }
194 sub accessor { $_[0]->{accessor} }
195 sub reader { $_[0]->{reader} }
196 sub writer { $_[0]->{writer} }
197 sub predicate { $_[0]->{predicate} }
198 sub clearer { $_[0]->{clearer} }
199 sub handles { $_[0]->{handles} }
201 sub _is_metadata { $_[0]->{is} }
202 sub is_required { $_[0]->{required} }
203 sub default { $_[0]->{default} }
204 sub is_lazy { $_[0]->{lazy} }
205 sub is_lazy_build { $_[0]->{lazy_build} }
206 sub is_weak_ref { $_[0]->{weak_ref} }
207 sub init_arg { $_[0]->{init_arg} }
208 sub type_constraint { $_[0]->{type_constraint} }
210 sub trigger { $_[0]->{trigger} }
211 sub builder { $_[0]->{builder} }
212 sub should_auto_deref { $_[0]->{auto_deref} }
213 sub should_coerce { $_[0]->{coerce} }
215 sub documentation { $_[0]->{documentation} }
219 sub has_accessor { exists $_[0]->{accessor} }
220 sub has_reader { exists $_[0]->{reader} }
221 sub has_writer { exists $_[0]->{writer} }
222 sub has_predicate { exists $_[0]->{predicate} }
223 sub has_clearer { exists $_[0]->{clearer} }
224 sub has_handles { exists $_[0]->{handles} }
226 sub has_default { exists $_[0]->{default} }
227 sub has_type_constraint { exists $_[0]->{type_constraint} }
228 sub has_trigger { exists $_[0]->{trigger} }
229 sub has_builder { exists $_[0]->{builder} }
231 sub has_documentation { exists $_[0]->{documentation} }
233 sub accessor_metaclass(){ 'Mouse::Meta::Method::Accessor' }
236 Mouse::Meta::TypeConstraint;
238 sub name { $_[0]->{name} }
239 sub parent { $_[0]->{parent} }
240 sub message { $_[0]->{message} }
242 sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} }
244 sub _compiled_type_coercion { $_[0]->{_compiled_type_coercion} }
247 sub has_coercion{ exists $_[0]->{_compiled_type_coercion} }