r880 - in packages/libclass-inspector-perl/trunk: . debian lib/Class t

Gunnar Wolf gwolf@costa.debian.org
Tue, 05 Apr 2005 22:29:47 +0000


Author: gwolf
Date: 2005-04-05 22:29:47 +0000 (Tue, 05 Apr 2005)
New Revision: 880

Modified:
   packages/libclass-inspector-perl/trunk/Changes
   packages/libclass-inspector-perl/trunk/MANIFEST
   packages/libclass-inspector-perl/trunk/META.yml
   packages/libclass-inspector-perl/trunk/Makefile.PL
   packages/libclass-inspector-perl/trunk/README
   packages/libclass-inspector-perl/trunk/debian/changelog
   packages/libclass-inspector-perl/trunk/lib/Class/Inspector.pm
   packages/libclass-inspector-perl/trunk/t/01_main.t
Log:
New upstream version


Modified: packages/libclass-inspector-perl/trunk/Changes
===================================================================
--- packages/libclass-inspector-perl/trunk/Changes	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/Changes	2005-04-05 22:29:47 UTC (rev 880)
@@ -1,5 +1,12 @@
 Revision history for Perl extension Class::Inspector.
 
+1.08 Tue Feb 15 2005
+	- Removing braindead Build.PL
+
+1.07 Thu Nov 18 2004
+	- Improved the speed (slightly, and only in positive cases) and accuracy of ->loaded.
+	- It now checks for some additional clues before returning false.
+
 1.06 Wed Jul 21 2004
 	- Fixed a major Win32 bug
 

Modified: packages/libclass-inspector-perl/trunk/MANIFEST
===================================================================
--- packages/libclass-inspector-perl/trunk/MANIFEST	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/MANIFEST	2005-04-05 22:29:47 UTC (rev 880)
@@ -5,4 +5,4 @@
 MANIFEST			This list of files
 README
 t/01_main.t
-META.yml                                Module meta-data (added by MakeMaker)
+META.yml                                 Module meta-data (added by MakeMaker)

Modified: packages/libclass-inspector-perl/trunk/META.yml
===================================================================
--- packages/libclass-inspector-perl/trunk/META.yml	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/META.yml	2005-04-05 22:29:47 UTC (rev 880)
@@ -1,12 +1,12 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         Class-Inspector
-version:      1.06
+version:      1.08
 version_from: lib/Class/Inspector.pm
 installdirs:  site
 requires:
     File::Spec:                    0.82
-    Test::More:                    0
+    Test::More:                    0.47
 
 distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.16
+generated_by: ExtUtils::MakeMaker version 6.17

Modified: packages/libclass-inspector-perl/trunk/Makefile.PL
===================================================================
--- packages/libclass-inspector-perl/trunk/Makefile.PL	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/Makefile.PL	2005-04-05 22:29:47 UTC (rev 880)
@@ -5,10 +5,10 @@
 	'VERSION_FROM' => 'lib/Class/Inspector.pm',
 	'PREREQ_PM'    => {
 		# Module dependencies
-		'File::Spec'   => 0.82,
+		'File::Spec'   => '0.82',
 
 		# Test file dependencies
-		'Test::More'   => 0,
+		'Test::More'   => '0.47',
 	},
 	($] >= 5.005) ? (
 		'AUTHOR'     => 'Adam Kennedy (cpan@ali.as)',

Modified: packages/libclass-inspector-perl/trunk/README
===================================================================
--- packages/libclass-inspector-perl/trunk/README	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/README	2005-04-05 22:29:47 UTC (rev 880)
@@ -35,7 +35,7 @@
 
   loaded $class
     Tries to determine if a class is loaded by looking for symbol table
-    entries. This method will work even if the class does not have it's own
+    entries. This method will work even if the class does not have its own
     file, but is contained inside a single file with multiple classes in it.
     Even in the case of some sort of run-time loading class being used,
     these typically leave some trace in the symbol table, so an "Autoload"
@@ -64,7 +64,7 @@
   loaded_filename $class
     For a given, loaded, class, returns the name of the file that it was
     originally loaded from. Returns false if the class is not loaded, or did
-    not have it's own file.
+    not have its own file.
 
   functions $class
     Returns a list of the names of all the functions in the classes
@@ -143,14 +143,13 @@
 SUPPORT
     Bugs should be reported via the CPAN bug tracker
 
-      http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class%3A%3AInspector
+    <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class%3A%3AInspector>
 
-    For other issues, contact the author
+    For other issues, or commercial enhancement or support, contact the
+    author.
 
 AUTHOR
-            Adam Kennedy
-            cpan@ali.as
-            http://ali.as/
+    Adam Kennedy (Maintainer), <http://ali.as/>, cpan@ali.as
 
 SEE ALSO
     Class::Handle, which wraps this one

Modified: packages/libclass-inspector-perl/trunk/debian/changelog
===================================================================
--- packages/libclass-inspector-perl/trunk/debian/changelog	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/debian/changelog	2005-04-05 22:29:47 UTC (rev 880)
@@ -1,3 +1,9 @@
+libclass-inspector-perl (1.08-1) unstable; urgency=low
+
+  * New upstream release
+
+ -- Gunnar Wolf <gwolf@debian.org>  Tue,  5 Apr 2005 17:28:26 -0500
+
 libclass-inspector-perl (1.06-1) unstable; urgency=low
 
   * New upstream release.

Modified: packages/libclass-inspector-perl/trunk/lib/Class/Inspector.pm
===================================================================
--- packages/libclass-inspector-perl/trunk/lib/Class/Inspector.pm	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/lib/Class/Inspector.pm	2005-04-05 22:29:47 UTC (rev 880)
@@ -9,6 +9,8 @@
 # Almost everything in here can be done in other ways, but a lot
 # involve playing with special varables, symbol table, and the like.
 
+# Load Overhead: 236k
+
 # We don't want to use strict refs, since we do a lot of things in here
 # that arn't strict refs friendly.
 use strict 'vars', 'subs';
@@ -17,7 +19,7 @@
 # Globals
 use vars qw{$VERSION $RE_SYMBOL $RE_CLASS $UNIX};
 BEGIN {
-	$VERSION = '1.06';
+	$VERSION = '1.08';
 
 	# Predefine some regexs
 	$RE_SYMBOL  = qr/\A[^\W\d]\w*\z/;
@@ -45,17 +47,27 @@
 
 # Is the class loaded.
 # We do this by seeing if the namespace is "occupied", which basically
-# means either we can find $VERSION, or any symbols other than child
-# symbol table branches exist.
+# means either we can find $VERSION or @ISA, or at least one subroutine.
 sub loaded {
 	my $class = shift;
 	my $name = $class->_class(shift) or return undef;
 
+	# Handle by far the two most common cases
+	# This is very fast and handles 99% of cases.
+	return 1 if defined ${"${name}::VERSION"};
+	return 1 if defined @{"${name}::ISA"};
+
 	# Are there any symbol table entries other than other namespaces
 	foreach ( keys %{"${name}::"} ) {
-		return 1 unless substr($_, -2, 2) eq '::';
+		next if substr($_, -2, 2) eq '::';
+		return 1 if defined &{"${name}::$_"};
 	}
 
+	# No functions, and it doesn't have a version, and isn't anything.
+	# As an absolute last resort, check for an entry in %INC
+	my $filename = $class->_inc_filename($name);
+	return 1 if defined $INC{$filename};
+
 	'';
 }
 
@@ -104,7 +116,7 @@
 # Only works if the class is loaded
 sub functions {
 	my $class = shift;
-	my $name = $class->_class(shift) or return undef;
+	my $name  = $class->_class(shift) or return undef;
 	return undef unless $class->loaded( $name );
 
 	# Get all the CODE symbol table entries
@@ -119,7 +131,7 @@
 # The class must be loaded for this to work.
 sub function_refs {
 	my $class = shift;
-	my $name = $class->_class(shift) or return undef;
+	my $name  = $class->_class(shift) or return undef;
 	return undef unless $class->loaded( $name );
 
 	# Get all the CODE symbol table entries, but return
@@ -133,21 +145,21 @@
 
 # Does a particular function exist
 sub function_exists {
-	my $class = shift;
-	my $name = $class->_class( shift ) or return undef;
+	my $class    = shift;
+	my $name     = $class->_class( shift ) or return undef;
 	my $function = shift or return undef;
 
 	# Only works if the class is loaded
 	return undef unless $class->loaded( $name );
 
-	# Does the GLOB exist and it's CODE part exist
+	# Does the GLOB exist and its CODE part exist
 	defined &{"${name}::$function"};
 }
 
 # Get all the available methods for the class
 sub methods {
-	my $class = shift;
-	my $name = $class->_class( shift ) or return undef;
+	my $class     = shift;
+	my $name      = $class->_class( shift ) or return undef;
 	my @arguments = map { lc $_ } @_;
 
 	# Process the arguments to determine the options
@@ -229,14 +241,14 @@
 #####################################################################
 # Children Related Methods
 
-# These can go undocumented for now, until I decide if it's best to
+# These can go undocumented for now, until I decide if its best to
 # just search the children in namespace only, or if I should do it via
 # the file system.
 
 # Find all the loaded classes below us
 sub children {
 	my $class = shift;
-	my $name = $class->_class(shift) or return ();
+	my $name  = $class->_class(shift) or return ();
 
 	# Find all the Foo:: elements in our symbol table
 	no strict 'refs';
@@ -245,8 +257,8 @@
 
 # As above, but recursively
 sub recursive_children {
-	my $class = shift;
-	my $name = $class->_class(shift) or return ();
+	my $class    = shift;
+	my $name     = $class->_class(shift) or return ();
 	my @children = ( $name );
 
 	# Do the search using a nicer, more memory efficient 
@@ -273,7 +285,7 @@
 # Checks and expands ( if needed ) a class name
 sub _class {
 	my $class = shift;
-	my $name = shift or return '';
+	my $name  = shift or return '';
 
 	# Handle main shorthand
 	return 'main' if $name eq '::';
@@ -287,7 +299,7 @@
 # regardless of platform.
 sub _inc_filename {
 	my $class = shift;
-	my $name = $class->_class(shift) or return undef;
+	my $name  = $class->_class(shift) or return undef;
 	join( '/', split /(?:'|::)/, $name ) . '.pm';
 }
 
@@ -353,7 +365,7 @@
 =head2 loaded $class
 
 Tries to determine if a class is loaded by looking for symbol table entries.
-This method will work even if the class does not have it's own file, but is
+This method will work even if the class does not have its own file, but is
 contained inside a single file with multiple classes in it. Even in the
 case of some sort of run-time loading class being used, these typically
 leave some trace in the symbol table, so an C<Autoload> or C<Class::Autouse>
@@ -382,7 +394,7 @@
 =head2 loaded_filename $class
 
 For a given, loaded, class, returns the name of the file that it was originally
-loaded from. Returns false if the class is not loaded, or did not have it's own
+loaded from. Returns false if the class is not loaded, or did not have its own
 file.
 
 =head2 functions $class
@@ -472,15 +484,13 @@
 
 Bugs should be reported via the CPAN bug tracker
 
-  http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class%3A%3AInspector
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class%3A%3AInspector>
 
-For other issues, contact the author
+For other issues, or commercial enhancement or support, contact the author.
 
 =head1 AUTHOR
 
-        Adam Kennedy
-        cpan@ali.as
-        http://ali.as/
+Adam Kennedy (Maintainer), L<http://ali.as/>, cpan@ali.as
 
 =head1 SEE ALSO
 

Modified: packages/libclass-inspector-perl/trunk/t/01_main.t
===================================================================
--- packages/libclass-inspector-perl/trunk/t/01_main.t	2005-04-05 22:28:06 UTC (rev 879)
+++ packages/libclass-inspector-perl/trunk/t/01_main.t	2005-04-05 22:29:47 UTC (rev 880)
@@ -5,11 +5,20 @@
 # Do all the tests on ourself, since we know we will be loaded.
 
 use strict;
-use lib '../../modules'; # Development testing
-use lib '../lib';           # Installation testing
+use lib ();
 use UNIVERSAL 'isa';
-use Test::More tests => 50;
+use File::Spec::Functions ':ALL';
+BEGIN {
+	$| = 1;
+	unless ( $ENV{HARNESS_ACTIVE} ) {
+		require FindBin;
+		chdir ($FindBin::Bin = $FindBin::Bin); # Avoid a warning
+		lib->import( catdir( updir(), updir(), 'modules') );
+	}
+}
 
+use Test::More tests => 51;
+
 # Set up any needed globals
 use vars qw{$loaded $ci $bad $base_functions $base_public};
 BEGIN {
@@ -259,4 +268,18 @@
 	"Public + Expanded ->methods works for inheriting class" );
 ok( ! $ci->methods( $bad ), "Expanded ->methods fails correctly" );
 
-# Done
+
+
+
+
+#####################################################################
+# Regression Tests
+
+# Discovered in 1.06, fixed in 1.07
+# In some cases, spurious empty GLOB entries can be created in a package.
+# These contain no actual symbols, but were causing ->loaded to return true.
+# An empty namespace with a single spurious empty glob entry (although
+# created in this test with a scalar) should return FALSE for ->loaded
+$Class::Inspector::SpuriousPackage::something = 1;
+ok( ! Class::Inspector->loaded('Class::Inspector::SpuriousPackage'),
+	'->loaded returns false for spurious glob in package' );