1 package Mouse::PurePerl;
9 use warnings FATAL => 'redefine'; # to avoid to load Mouse::PurePerl
16 return 0 if ref($class) || !defined($class) || !length($class);
18 # walk the symbol table tree to avoid autovififying
19 # \*{${main::}{"Foo::"}} == \*main::Foo::
22 foreach my $part (split('::', $class)) {
23 my $entry = \$pack->{$part . '::'};
24 return 0 if ref($entry) ne 'GLOB';
25 $pack = *{$entry}{HASH} or return 0;
28 # check for $VERSION or @ISA
29 return 1 if exists $pack->{VERSION}
30 && defined *{$pack->{VERSION}}{SCALAR} && defined ${ $pack->{VERSION} };
31 return 1 if exists $pack->{ISA}
32 && defined *{$pack->{ISA}}{ARRAY} && @{ $pack->{ISA} } != 0;
34 # check for any method
35 foreach my $name( keys %{$pack} ) {
36 my $entry = \$pack->{$name};
37 return 1 if ref($entry) ne 'GLOB' || defined *{$entry}{CODE};
45 # taken from Sub::Identify
48 ref($coderef) or return;
50 my $cv = B::svref_2object($coderef);
51 $cv->isa('B::CV') or return;
54 $gv->isa('B::GV') or return;
56 return ($gv->STASH->NAME, $gv->NAME);
62 my $cv = B::svref_2object($coderef);
63 $cv->isa('B::CV') or return '';
66 $gv->isa('B::GV') or return '';
68 return $gv->STASH->NAME;
72 my($package, $name) = @_;
75 use warnings FATAL => 'uninitialized';
76 return *{$package . '::' . $name}{CODE};
80 Mouse::Util::TypeConstraints;
82 use Scalar::Util qw(blessed looks_like_number openhandle);
84 sub _generate_class_type_for{
85 my($for_class, $name) = @_;
87 my $predicate = sub{ blessed($_[0]) && $_[0]->isa($for_class) };
91 *{ caller() . '::' . $name } = $predicate;
102 sub Bool { $_[0] ? $_[0] eq '1' : 1 }
103 sub Undef { !defined($_[0]) }
104 sub Defined { defined($_[0]) }
105 sub Value { defined($_[0]) && !ref($_[0]) }
106 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
107 sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
108 sub Str { defined($_[0]) && !ref($_[0]) }
110 sub Ref { ref($_[0]) }
111 sub ScalarRef { ref($_[0]) eq 'SCALAR' }
112 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
113 sub HashRef { ref($_[0]) eq 'HASH' }
114 sub CodeRef { ref($_[0]) eq 'CODE' }
115 sub RegexpRef { ref($_[0]) eq 'Regexp' }
116 sub GlobRef { ref($_[0]) eq 'GLOB' }
119 openhandle($_[0]) || (blessed($_[0]) && $_[0]->isa("IO::Handle"))
122 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
124 sub ClassName { Mouse::Util::is_class_loaded($_[0]) }
125 sub RoleName { (Mouse::Util::class_of($_[0]) || return 0)->isa('Mouse::Meta::Role') }
131 sub name { $_[0]->{package} }
133 sub _method_map { $_[0]->{methods} }
134 sub _attribute_map{ $_[0]->{attribute_map} }
137 my $name = $_[0]->{package};
139 return \%{ $name . '::' };
143 my($self, $name, $code) = @_;
146 $self->throw_error('You must pass a defined name');
149 $self->throw_error('You must pass a defined code');
152 if(ref($code) ne 'CODE'){
153 $code = \&{$code}; # coerce
156 $self->{methods}->{$name} = $code; # Moose stores meta object here.
158 my $pkg = $self->name;
160 no warnings 'redefine', 'once';
161 *{ $pkg . '::' . $name } = $code;
170 return exists $_[0]->{anon_serial_id};
173 sub roles { $_[0]->{roles} }
175 sub linearized_isa { @{ get_linear_isa($_[0]->{package}) } }
181 return exists $_[0]->{anon_serial_id};
184 sub get_roles { $_[0]->{roles} }
187 Mouse::Meta::Attribute;
189 use Mouse::Meta::Method::Accessor;
193 sub name { $_[0]->{name} }
194 sub associated_class { $_[0]->{associated_class} }
196 sub accessor { $_[0]->{accessor} }
197 sub reader { $_[0]->{reader} }
198 sub writer { $_[0]->{writer} }
199 sub predicate { $_[0]->{predicate} }
200 sub clearer { $_[0]->{clearer} }
201 sub handles { $_[0]->{handles} }
203 sub _is_metadata { $_[0]->{is} }
204 sub is_required { $_[0]->{required} }
205 sub default { $_[0]->{default} }
206 sub is_lazy { $_[0]->{lazy} }
207 sub is_lazy_build { $_[0]->{lazy_build} }
208 sub is_weak_ref { $_[0]->{weak_ref} }
209 sub init_arg { $_[0]->{init_arg} }
210 sub type_constraint { $_[0]->{type_constraint} }
212 sub trigger { $_[0]->{trigger} }
213 sub builder { $_[0]->{builder} }
214 sub should_auto_deref { $_[0]->{auto_deref} }
215 sub should_coerce { $_[0]->{coerce} }
217 sub documentation { $_[0]->{documentation} }
221 sub has_accessor { exists $_[0]->{accessor} }
222 sub has_reader { exists $_[0]->{reader} }
223 sub has_writer { exists $_[0]->{writer} }
224 sub has_predicate { exists $_[0]->{predicate} }
225 sub has_clearer { exists $_[0]->{clearer} }
226 sub has_handles { exists $_[0]->{handles} }
228 sub has_default { exists $_[0]->{default} }
229 sub has_type_constraint { exists $_[0]->{type_constraint} }
230 sub has_trigger { exists $_[0]->{trigger} }
231 sub has_builder { exists $_[0]->{builder} }
233 sub has_documentation { exists $_[0]->{documentation} }
235 sub accessor_metaclass(){ 'Mouse::Meta::Method::Accessor' }
238 Mouse::Meta::TypeConstraint;
240 sub name { $_[0]->{name} }
241 sub parent { $_[0]->{parent} }
242 sub message { $_[0]->{message} }
244 sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} }
246 sub _compiled_type_coercion { $_[0]->{_compiled_type_coercion} }
248 sub has_coercion{ exists $_[0]->{_compiled_type_coercion} }
255 Mouse::PurePerl - A Mouse guts in pure Perl
259 This document describes Mouse version 0.40_02