20 # We only have to do this nastiness if we haven't loaded XS version of
21 # Mouse.pm, so check if we're running under PurePerl or not
26 # VVVVV CODE TAKEN FROM SCALAR::UTIL VVVVV
28 *UNIVERSAL::a_sub_not_likely_to_be_here = sub {
31 # deviation from Scalar::Util
32 # XS returns undef, PP returns GLOB.
33 # let's make that more consistent by having PP return
34 # undef if it's a GLOB. :/
36 # \*STDOUT would be allowed as an object in PP blessed
38 return $ref eq 'GLOB' ? undef : $ref;
42 local($@, $SIG{__DIE__}, $SIG{__WARN__});
44 ? eval { $_[0]->a_sub_not_likely_to_be_here }
48 'looks_like_number' => sub {
51 # checks from perlfaq4
52 return 0 if !defined($_) or ref($_);
53 return 1 if (/^[+-]?\d+$/); # is a +/- integer
54 return 1 if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/); # a C float
55 return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i);
60 local($@, $SIG{__DIE__}, $SIG{__WARN__});
64 length($t = ref($r)) or return undef;
66 # This eval will fail if the reference is not blessed
67 eval { $r->a_sub_not_likely_to_be_here; 1 }
70 # we have a GLOB or an IO. Stringify a GLOB gives it's name
72 $q =~ /^\*/ ? "GLOB" : "IO";
75 # OK, if we don't have a GLOB what parts of
76 # a glob will it populate.
77 # NOTE: A glob always has a SCALAR
79 defined *glob{ARRAY} && "ARRAY"
80 or defined *glob{HASH} && "HASH"
81 or defined *glob{CODE} && "CODE"
82 or length(ref(${$r})) ? "REF" : "SCALAR";
89 my $rt = reftype($fh) || '';
91 return defined(fileno($fh)) ? $fh : undef
94 if (reftype(\$fh) eq 'GLOB') { # handle openhandle(*DATA)
97 elsif ($rt ne 'GLOB') {
101 (tied(*$fh) or defined(fileno($fh)))
105 loaded => \&Scalar::Util::weaken,
106 not_loaded => sub { die "Scalar::Util required for weak reference support" },
108 # ^^^^^ CODE TAKEN FROM SCALAR::UTIL ^^^^^
111 # VVVVV CODE TAKEN FROM MRO::COMPAT VVVVV
112 'get_linear_isa' => {
113 loaded => \&mro::get_linear_isa,
115 # this recurses so it isn't pretty
120 my $classname = shift;
122 my @lin = ($classname);
124 foreach my $parent (@{"$classname\::ISA"}) {
125 my $plin = $code->($parent);
127 next if exists $stored{$_};
136 # ^^^^^ CODE TAKEN FROM MRO::COMPAT ^^^^^
142 our @EXPORT_OK = map { keys %$_ } values %dependencies;
145 test => [qw/throws_ok lives_ok dies_ok/],
148 for my $module (keys %dependencies) {
149 my ($module_name, $version) = split ' ', $module;
152 local $SIG{__DIE__} = 'DEFAULT';
153 eval "use $module (); 1";
156 $loaded{$module_name} = $loaded;
158 for my $method_name (keys %{ $dependencies{ $module } }) {
159 my $producer = $dependencies{$module}{$method_name};
162 if (ref($producer) eq 'HASH') {
163 $implementation = $loaded
164 ? $producer->{loaded}
165 : $producer->{not_loaded};
168 $implementation = $loaded
169 ? $module_name->can($method_name)
174 *{ __PACKAGE__ . '::' . $method_name } = $implementation;
179 sub apply_all_roles {
180 my $meta = Mouse::Meta::Class->initialize(shift);
183 my $max = scalar(@_);
184 for (my $i = 0; $i < $max ; $i++) {
185 if ($i + 1 < $max && ref($_[$i + 1])) {
186 push @roles, [ $_[$i++] => $_[$i] ];
188 push @roles, [ $_[$i] => {} ];
192 foreach my $role_spec (@roles) {
193 Mouse::load_class( $role_spec->[0] );
196 ( $_->[0]->can('meta') && $_->[0]->meta->isa('Mouse::Meta::Role') )
197 || croak("You can only consume roles, "
199 . " is not a Moose role")
202 if ( scalar @roles == 1 ) {
203 my ( $role, $params ) = @{ $roles[0] };
204 $role->meta->apply( $meta, ( defined $params ? %$params : () ) );
207 Mouse::Meta::Role->combine_apply($meta, @roles);
218 Mouse::Util - features, with or without their dependencies
220 =head1 IMPLEMENTATIONS FOR
222 =head2 L<MRO::Compat>
224 =head3 get_linear_isa
226 =head2 L<Scalar::Util>
230 =head3 looks_like_number
238 C<weaken> I<must> be implemented in XS. If the user tries to use C<weaken>
239 without L<Scalar::Util>, an error is thrown.
241 =head2 Test::Exception