10 # VVVVV CODE TAKEN FROM SCALAR::UTIL VVVVV
14 *UNIVERSAL::a_sub_not_likely_to_be_here = sub {
17 # deviation from Scalar::Util
18 # XS returns undef, PP returns GLOB.
19 # let's make that more consistent by having PP return
20 # undef if it's a GLOB. :/
22 # \*STDOUT would be allowed as an object in PP blessed
24 return $ref eq 'GLOB' ? undef : $ref;
29 local($@, $SIG{__DIE__}, $SIG{__WARN__});
31 ? eval { $_[0]->a_sub_not_likely_to_be_here }
35 'looks_like_number' => sub {
38 # checks from perlfaq4
39 return 0 if !defined($_) or ref($_);
40 return 1 if (/^[+-]?\d+$/); # is a +/- integer
41 return 1 if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/); # a C float
42 return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i);
47 local($@, $SIG{__DIE__}, $SIG{__WARN__});
51 length($t = ref($r)) or return undef;
53 # This eval will fail if the reference is not blessed
54 eval { $r->a_sub_not_likely_to_be_here; 1 }
57 # we have a GLOB or an IO. Stringify a GLOB gives it's name
59 $q =~ /^\*/ ? "GLOB" : "IO";
62 # OK, if we don't have a GLOB what parts of
63 # a glob will it populate.
64 # NOTE: A glob always has a SCALAR
66 defined *glob{ARRAY} && "ARRAY"
67 or defined *glob{HASH} && "HASH"
68 or defined *glob{CODE} && "CODE"
69 or length(ref(${$r})) ? "REF" : "SCALAR";
76 my $rt = reftype($fh) || '';
78 return defined(fileno($fh)) ? $fh : undef
81 if (reftype(\$fh) eq 'GLOB') { # handle openhandle(*DATA)
84 elsif ($rt ne 'GLOB') {
88 (tied(*$fh) or defined(fileno($fh)))
92 loaded => \&Scalar::Util::weaken,
93 not_loaded => sub { die "Scalar::Util required for weak reference support" },
95 # ^^^^^ CODE TAKEN FROM SCALAR::UTIL ^^^^^
98 # VVVVV CODE TAKEN FROM MRO::COMPAT VVVVV
100 loaded => \&mro::get_linear_isa,
102 # this recurses so it isn't pretty
107 my $classname = shift;
109 my @lin = ($classname);
111 foreach my $parent (@{"$classname\::ISA"}) {
112 my $plin = $code->($parent);
114 next if exists $stored{$_};
123 # ^^^^^ CODE TAKEN FROM MRO::COMPAT ^^^^^
127 our @EXPORT_OK = map { keys %$_ } values %dependencies;
129 for my $module_name (keys %dependencies) {
130 (my $file = "$module_name.pm") =~ s{::}{/}g;
133 local $SIG{__DIE__} = 'DEFAULT';
134 eval "require '$file'; 1";
137 for my $method_name (keys %{ $dependencies{ $module_name } }) {
138 my $producer = $dependencies{$module_name}{$method_name};
141 if (ref($producer) eq 'HASH') {
142 $implementation = $loaded
143 ? $producer->{loaded}
144 : $producer->{not_loaded};
147 $implementation = $loaded
148 ? $module_name->can($method_name)
153 *{ __PACKAGE__ . '::' . $method_name } = $implementation;
164 Mouse::Util - features, with or without their dependencies
166 =head1 IMPLEMENTATIONS FOR
168 =head2 L<MRO::Compat>
170 =head3 get_linear_isa
172 =head2 L<Scalar::Util>
176 =head3 looks_like_number
184 C<weaken> I<must> be implemented in XS. If the user tries to use C<weaken>
185 without L<Scalar::Util>, an error is thrown.