Commits

Toby Inkster  committed b4de348

avoid UNIVERSAL::can($pkg, "can")

  • Participants
  • Parent commits d8c91be

Comments (0)

Files changed (3)

File lib/Scalar/Does.pm

 our %_CONSTANTS;
 BEGIN {
 	$Scalar::Does::AUTHORITY = 'cpan:TOBYINK';
-	$Scalar::Does::VERSION   = '0.009';
+	$Scalar::Does::VERSION   = '0.010';
 	
 	%_CONSTANTS = (
 		BOOLEAN    => q[bool],
 BEGIN {
 	package Scalar::Does::RoleChecker;
 	$Scalar::Does::RoleChecker::AUTHORITY = 'cpan:TOBYINK';
-	$Scalar::Does::RoleChecker::VERSION   = '0.009';
+	$Scalar::Does::RoleChecker::VERSION   = '0.010';
 	use overload
 		q[""]    => 'name',
 		q[&{}]   => 'code',

File lib/Scalar/Does/MooseTypes.pm

 package Scalar::Does::MooseTypes;
 
 our $AUTHORITY = 'cpan:TOBYINK';
-our $VERSION   = '0.009';
+our $VERSION   = '0.010';
 
 use Scalar::Does qw( blessed does looks_like_number -make );
 
+sub is_class_loaded {
+	return !!0 if ref $_[0];
+	my $stash = do { no strict 'refs'; \%{"$_[0]\::"} };
+	return !!1 if exists $stash->{'ISA'};
+	return !!1 if exists $stash->{'VERSION'};
+	foreach my $globref (values %$stash) {
+		return !!1 if *{$globref}{CODE};
+	}
+	return !!0;
+}
+
 my @ROLES;
 my @NAMES;
 BEGIN {
 		make_role('GlobRef',   sub { ref $_[0] eq 'GLOB' }),
 		make_role('FileHandle',sub { require IO::Detect; IO::Detect::is_filehandle($_[0]) }),
 		make_role('Object',    sub { blessed($_[0]) }),
-		make_role('ClassName', sub { !ref($_[0]) && UNIVERSAL::can($_[0], 'can') }),
-		make_role('RoleName',  sub { !ref($_[0]) && UNIVERSAL::can($_[0], 'can') }),
+		make_role('ClassName', \&is_class_loaded),
+		make_role('RoleName',  \&is_class_loaded),
 		make_role('ScalarRef', sub { ref $_[0] eq 'SCALAR' || ref $_[0] eq 'REF' }),
 		make_role('ArrayRef',  sub { ref $_[0] eq 'ARRAY' }),
 		make_role('HashRef',   sub { ref $_[0] eq 'HASH' }),

File meta/changes.pret

 		item "Requires UNIVERSAL::DOES in Perl < 5.010."^^Packaging;
 		item "use if $] < 5.010, 'UNIVERSAL::DOES'."^^Bugfix;
 	].
+
+`Scalar-Does 0.010 cpan:TOBYINK`
+	issued  2012-12-05;
+	changeset [
+		item [
+			a dcs:Update;
+			dcs:fixes RT#81622;
+			label "Perl 5.17 has changed the behaviour of UNIVERSAL::can($pkg, 'can'), so that it is no longer useful for detecting whether a package is loaded. Changed Scalar::Does::MooseLike to avoid this idiom.";
+		];
+	].