Remove useless check code
[gitmo/Mouse.git] / lib / Mouse / PurePerl.pm
CommitLineData
df6dd016 1package
2 Mouse::Util;
3
4use strict;
5use warnings;
6
7use warnings FATAL => 'redefine'; # to avoid to load Mouse::PurePerl
8
9use B ();
10
11sub is_class_loaded {
12 my $class = shift;
13
14 return 0 if ref($class) || !defined($class) || !length($class);
15
16 # walk the symbol table tree to avoid autovififying
17 # \*{${main::}{"Foo::"}} == \*main::Foo::
18
19 my $pack = \%::;
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;
24 }
25
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;
31
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};
36 }
37
38 # fail
39 return 0;
40}
41
42
43# taken from Sub::Identify
44sub get_code_info {
45 my ($coderef) = @_;
46 ref($coderef) or return;
47
48 my $cv = B::svref_2object($coderef);
49 $cv->isa('B::CV') or return;
50
51 my $gv = $cv->GV;
52 $gv->isa('B::GV') or return;
53
54 return ($gv->STASH->NAME, $gv->NAME);
55}
56
57sub get_code_package{
58 my($coderef) = @_;
59
60 my $cv = B::svref_2object($coderef);
61 $cv->isa('B::CV') or return '';
62
63 my $gv = $cv->GV;
64 $gv->isa('B::GV') or return '';
65
66 return $gv->STASH->NAME;
67}
68
43165725 69package
70 Mouse::Meta::Module;
71
72sub name { $_[0]->{package} }
73
2591e962 74sub namespace{
75 my $name = $_[0]->{package};
76 no strict 'refs';
77 return \%{ $name . '::' };
78}
79
43165725 80package
81 Mouse::Meta::Class;
82
83sub is_anon_class{
84 return exists $_[0]->{anon_serial_id};
85}
86
87sub roles { $_[0]->{roles} }
88
cccb83de 89sub linearized_isa { @{ get_linear_isa($_[0]->{package}) } }
90
43165725 91package
92 Mouse::Meta::Role;
93
94sub is_anon_role{
95 return exists $_[0]->{anon_serial_id};
96}
97
98sub get_roles { $_[0]->{roles} }
99
100package
101 Mouse::Meta::Attribute;
102
103
104# readers
105
106sub name { $_[0]->{name} }
107sub associated_class { $_[0]->{associated_class} }
108
109sub accessor { $_[0]->{accessor} }
110sub reader { $_[0]->{reader} }
111sub writer { $_[0]->{writer} }
112sub predicate { $_[0]->{predicate} }
113sub clearer { $_[0]->{clearer} }
114sub handles { $_[0]->{handles} }
115
116sub _is_metadata { $_[0]->{is} }
117sub is_required { $_[0]->{required} }
118sub default { $_[0]->{default} }
119sub is_lazy { $_[0]->{lazy} }
120sub is_lazy_build { $_[0]->{lazy_build} }
121sub is_weak_ref { $_[0]->{weak_ref} }
122sub init_arg { $_[0]->{init_arg} }
123sub type_constraint { $_[0]->{type_constraint} }
124
125sub trigger { $_[0]->{trigger} }
126sub builder { $_[0]->{builder} }
127sub should_auto_deref { $_[0]->{auto_deref} }
128sub should_coerce { $_[0]->{coerce} }
129
130# predicates
131
132sub has_accessor { exists $_[0]->{accessor} }
133sub has_reader { exists $_[0]->{reader} }
134sub has_writer { exists $_[0]->{writer} }
135sub has_predicate { exists $_[0]->{predicate} }
136sub has_clearer { exists $_[0]->{clearer} }
137sub has_handles { exists $_[0]->{handles} }
138
139sub has_default { exists $_[0]->{default} }
140sub has_type_constraint { exists $_[0]->{type_constraint} }
141sub has_trigger { exists $_[0]->{trigger} }
142sub has_builder { exists $_[0]->{builder} }
143
144package
145 Mouse::Meta::TypeConstraint;
146
147sub name { $_[0]->{name} }
148sub parent { $_[0]->{parent} }
149sub message { $_[0]->{message} }
150
151sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} }
152
153sub has_coercion{ exists $_[0]->{_compiled_type_coercion} }
df6dd016 154
155package
156 Mouse::Meta::Method::Accessor;
157
1581;
159__END__