r56343 - in /branches/upstream/libmodule-runtime-perl: ./ current/ current/lib/ current/lib/Module/ current/t/

ivan at users.alioth.debian.org ivan at users.alioth.debian.org
Sun Apr 18 01:59:51 UTC 2010


Author: ivan
Date: Sun Apr 18 01:59:33 2010
New Revision: 56343

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=56343
Log:
[svn-inject] Installing original source of libmodule-runtime-perl

Added:
    branches/upstream/libmodule-runtime-perl/
    branches/upstream/libmodule-runtime-perl/current/
    branches/upstream/libmodule-runtime-perl/current/.cvsignore
    branches/upstream/libmodule-runtime-perl/current/Build.PL
    branches/upstream/libmodule-runtime-perl/current/Changes
    branches/upstream/libmodule-runtime-perl/current/MANIFEST
    branches/upstream/libmodule-runtime-perl/current/META.yml
    branches/upstream/libmodule-runtime-perl/current/Makefile.PL
    branches/upstream/libmodule-runtime-perl/current/README
    branches/upstream/libmodule-runtime-perl/current/SIGNATURE
    branches/upstream/libmodule-runtime-perl/current/lib/
    branches/upstream/libmodule-runtime-perl/current/lib/Module/
    branches/upstream/libmodule-runtime-perl/current/lib/Module/Runtime.pm
    branches/upstream/libmodule-runtime-perl/current/t/
    branches/upstream/libmodule-runtime-perl/current/t/Mod0.pm
    branches/upstream/libmodule-runtime-perl/current/t/Mod1.pm
    branches/upstream/libmodule-runtime-perl/current/t/cmn.t
    branches/upstream/libmodule-runtime-perl/current/t/ivmn.t
    branches/upstream/libmodule-runtime-perl/current/t/ivms.t
    branches/upstream/libmodule-runtime-perl/current/t/pod_cvg.t
    branches/upstream/libmodule-runtime-perl/current/t/pod_syn.t
    branches/upstream/libmodule-runtime-perl/current/t/rm.t
    branches/upstream/libmodule-runtime-perl/current/t/um.t
    branches/upstream/libmodule-runtime-perl/current/t/upo.t

Added: branches/upstream/libmodule-runtime-perl/current/.cvsignore
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/.cvsignore?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/.cvsignore (added)
+++ branches/upstream/libmodule-runtime-perl/current/.cvsignore Sun Apr 18 01:59:33 2010
@@ -1,0 +1,4 @@
+Build Makefile
+_build blib
+META.yml Makefile.PL SIGNATURE
+Module-Runtime-*

Added: branches/upstream/libmodule-runtime-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/Build.PL?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/Build.PL (added)
+++ branches/upstream/libmodule-runtime-perl/current/Build.PL Sun Apr 18 01:59:33 2010
@@ -1,0 +1,35 @@
+{ use 5.006; }
+use warnings;
+use strict;
+
+use Module::Build;
+
+Module::Build->new(
+	module_name => "Module::Runtime",
+	license => "perl",
+	configure_requires => {
+		"Module::Build" => 0,
+		"perl" => "5.006",
+	},
+	build_requires => {
+		"Module::Build" => 0,
+		"Test::More" => 0,
+		"perl" => "5.006",
+		"strict" => 0,
+		"warnings" => 0,
+	},
+	requires => {
+		"Exporter" => 0,
+		"Params::Classify" => 0,
+		"parent" => 0,
+		"perl" => "5.006",
+		"strict" => 0,
+		"warnings" => 0,
+	},
+	dynamic_config => 0,
+	meta_add => { distribution_type => "module" },
+	create_makefile_pl => "passthrough",
+	sign => 1,
+)->create_build_script;
+
+1;

Added: branches/upstream/libmodule-runtime-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/Changes?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/Changes (added)
+++ branches/upstream/libmodule-runtime-perl/current/Changes Sun Apr 18 01:59:33 2010
@@ -1,0 +1,87 @@
+version 0.007; 2010-03-19
+
+  * add "check_" functions for argument checking
+
+  * supply regexps to check module name and spec syntax
+
+  * in "is_" functions, also cleanly handle non-string arguments
+
+  * in require_module() (also affecting use_module()), call require()
+    as a function (with appropriate name translation) instead of using
+    string eval, to avoid unnecessary complication of exception handling
+
+  * provide the "is_valid_" functions under shorter "is_" names
+
+  * revise POD markup
+
+  * check for required Perl version at runtime
+
+  * in tests, supply test modules to avoid requiring unrelated math
+    modules
+
+  * in Build.PL, explicitly declare configure-time requirements
+
+  * remove bogus "exit 0" from Build.PL
+
+version 0.006; 2009-05-19
+
+  * bugfix: avoid unreliable "\w" in regexps in code
+
+  * document that module name syntax is restricted to ASCII
+
+  * use simpler "parent" pragma in place of "base"
+
+  * in documentation, use the term "truth value" instead of the less
+    precise "boolean"
+
+  * use full stricture in Build.PL
+
+version 0.005; 2007-09-17
+
+  * bugfix: override any ambient $SIG{__DIE__} handler when using eval { }
+
+  * use "base" pragma to import Exporter behaviour
+
+  * test POD syntax and coverage, and rename an internal function to
+    satisfy the coverage test
+
+  * build with Module::Build instead of ExtUtils::MakeMaker
+
+  * complete dependency list
+
+  * include signature in distribution
+
+  * in documentation, separate "license" section from "copyright" section
+
+version 0.004; 2007-08-12
+
+  * change choice of module to test use_package_optimistically(), because
+    some old versions of Math::BigInt don't have a version number which
+    was causing a false test failure
+
+version 0.003; 2007-01-27
+
+  * loosen tests to work with perl v5.9's changed diagnostics
+
+version 0.002; 2006-06-15
+
+  * new function use_package_optimistically() to duplicate the "base"
+    pragma's quiet module loading
+
+  * insert missing bracket in documentation for use_module()
+
+version 0.001; 2004-10-29
+
+  * new function use_module()
+
+  * document return value of require_module()
+
+  * more stringent tests for the return value of require_module()
+
+  * explicitly declare lack of module dependencies in Makefile.PL
+
+  * include Changes file
+
+version 0.000; 2004-02-15
+
+  * initial released version

Added: branches/upstream/libmodule-runtime-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/MANIFEST?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/MANIFEST (added)
+++ branches/upstream/libmodule-runtime-perl/current/MANIFEST Sun Apr 18 01:59:33 2010
@@ -1,0 +1,19 @@
+.cvsignore
+Build.PL
+Changes
+MANIFEST
+META.yml
+Makefile.PL
+README
+lib/Module/Runtime.pm
+t/Mod0.pm
+t/Mod1.pm
+t/cmn.t
+t/ivmn.t
+t/ivms.t
+t/pod_cvg.t
+t/pod_syn.t
+t/rm.t
+t/um.t
+t/upo.t
+SIGNATURE    Added here by Module::Build

Added: branches/upstream/libmodule-runtime-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/META.yml?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/META.yml (added)
+++ branches/upstream/libmodule-runtime-perl/current/META.yml Sun Apr 18 01:59:33 2010
@@ -1,0 +1,35 @@
+---
+abstract: 'runtime module handling'
+author:
+  - 'Andrew Main (Zefram) <zefram at fysh.org>'
+build_requires:
+  Module::Build: 0
+  Test::More: 0
+  perl: 5.006
+  strict: 0
+  warnings: 0
+configure_requires:
+  Module::Build: 0
+  perl: 5.006
+distribution_type: module
+dynamic_config: 0
+generated_by: 'Module::Build version 0.3603'
+license: perl
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.4.html
+  version: 1.4
+name: Module-Runtime
+provides:
+  Module::Runtime:
+    file: lib/Module/Runtime.pm
+    version: 0.007
+requires:
+  Exporter: 0
+  Params::Classify: 0
+  parent: 0
+  perl: 5.006
+  strict: 0
+  warnings: 0
+resources:
+  license: http://dev.perl.org/licenses/
+version: 0.007

Added: branches/upstream/libmodule-runtime-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/Makefile.PL?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/Makefile.PL (added)
+++ branches/upstream/libmodule-runtime-perl/current/Makefile.PL Sun Apr 18 01:59:33 2010
@@ -1,0 +1,35 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.3603
+require 5.006;
+
+    unless (eval "use Module::Build::Compat 0.02; 1" ) {
+      print "This module requires Module::Build to install itself.\n";
+
+      require ExtUtils::MakeMaker;
+      my $yn = ExtUtils::MakeMaker::prompt
+	('  Install Module::Build now from CPAN?', 'y');
+
+      unless ($yn =~ /^y/i) {
+	die " *** Cannot install without Module::Build.  Exiting ...\n";
+      }
+
+      require Cwd;
+      require File::Spec;
+      require CPAN;
+
+      # Save this 'cause CPAN will chdir all over the place.
+      my $cwd = Cwd::cwd();
+
+      CPAN::Shell->install('Module::Build::Compat');
+      CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
+	or die "Couldn't install Module::Build, giving up.\n";
+
+      chdir $cwd or die "Cannot chdir() back to $cwd: $!";
+    }
+    eval "use Module::Build::Compat 0.02; 1" or die $@;
+    
+    Module::Build::Compat->run_build_pl(args => \@ARGV);
+    my $build_script = 'Build';
+    $build_script .= '.com' if $^O eq 'VMS';
+    exit(0) unless(-e $build_script); # cpantesters convention
+    require Module::Build;
+    Module::Build::Compat->write_makefile(build_class => 'Module::Build');

Added: branches/upstream/libmodule-runtime-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/README?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/README (added)
+++ branches/upstream/libmodule-runtime-perl/current/README Sun Apr 18 01:59:33 2010
@@ -1,0 +1,29 @@
+NAME
+
+Module::Runtime - runtime module handling
+
+DESCRIPTION
+
+The functions exported by this module deal with runtime handling of Perl
+modules, which are normally handled at compile time.
+
+INSTALLATION
+
+	perl Build.PL
+	./Build
+	./Build test
+	./Build install
+
+AUTHOR
+
+Andrew Main (Zefram) <zefram at fysh.org>
+
+COPYRIGHT
+
+Copyright (C) 2004, 2006, 2007, 2009, 2010
+Andrew Main (Zefram) <zefram at fysh.org>
+
+LICENSE
+
+This module is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.

Added: branches/upstream/libmodule-runtime-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/SIGNATURE?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/SIGNATURE (added)
+++ branches/upstream/libmodule-runtime-perl/current/SIGNATURE Sun Apr 18 01:59:33 2010
@@ -1,0 +1,41 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.61.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+    % cpansign -v
+
+It will check each file's integrity, as well as the signature's
+validity.  If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 b6d25225ba8a64214777140d46baa28efac5f182 .cvsignore
+SHA1 e909e0a1d479fd4ed3897aee5c8412951b232da4 Build.PL
+SHA1 6103e60866161c8c1513f336e4a9aced06597fa8 Changes
+SHA1 f76971807c061f8f771566271fc88b6da3602dff MANIFEST
+SHA1 cefaac62020f304df8b4d4a50ce1f0b31deceb9e META.yml
+SHA1 f8469f20cf26bafaffabb905631b945ab0f81289 Makefile.PL
+SHA1 a8fb1cf3c6b9aef90fceb32bdf029977af15cb0c README
+SHA1 e0961c44d0681ab618372d1209338b7ac0820134 lib/Module/Runtime.pm
+SHA1 15f83d769adddc47c9b7f41bfd1c8d109af030f5 t/Mod0.pm
+SHA1 c9ec963e8dc84fa17c79746429c5ca0224202dff t/Mod1.pm
+SHA1 d1daf64b7648733cfacf95e0152e94d8bcc3b8bf t/cmn.t
+SHA1 5cfcdf0696c7f54bb87f95d8926de5ec37398ef9 t/ivmn.t
+SHA1 d14755fedf4b4c07c3c615086402b0f91c960ba7 t/ivms.t
+SHA1 0e141eecf3ca4903ef38d9413b5403a9ddb0392f t/pod_cvg.t
+SHA1 74a957cd8b93f25672ecc6aa578a671d084dd343 t/pod_syn.t
+SHA1 04cb55e06d43ecda3d6325c63733c313a695d19f t/rm.t
+SHA1 b7586b4ec77aa462f1aaf87a87d4c03d75d34b97 t/um.t
+SHA1 6a69a3d943d5e800c0a913dd15335030437455ce t/upo.t
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.9 (GNU/Linux)
+
+iEYEARECAAYFAkuj8CwACgkQOV9mt2VyAVGPUQCfYIUqLgv8XofkAMNKb8IZKuD8
+zVMAoIbcwvqfEBcNvvk+g0DawFlCSpJU
+=FcY1
+-----END PGP SIGNATURE-----

Added: branches/upstream/libmodule-runtime-perl/current/lib/Module/Runtime.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/lib/Module/Runtime.pm?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/lib/Module/Runtime.pm (added)
+++ branches/upstream/libmodule-runtime-perl/current/lib/Module/Runtime.pm Sun Apr 18 01:59:33 2010
@@ -1,0 +1,377 @@
+=head1 NAME
+
+Module::Runtime - runtime module handling
+
+=head1 SYNOPSIS
+
+	use Module::Runtime qw(
+		$module_name_rx is_module_name check_module_name
+		require_module
+	);
+
+	if($module_name =~ /\A$module_name_rx\z/o) { ...
+	if(is_module_name($module_name)) { ...
+	check_module_name($module_name);
+
+	require_module($module_name);
+
+	use Module::Runtime qw(use_module use_package_optimistically);
+
+	$bi = use_module("Math::BigInt", 1.31)->new("1_234");
+	$widget = use_package_optimistically("Local::Widget")->new;
+
+	use Module::Runtime qw(
+		$top_module_spec_rx $sub_module_spec_rx
+		is_module_spec check_module_spec
+		compose_module_name
+	);
+
+	if($spec =~ /\A$top_module_spec_rx\z/o) { ...
+	if($spec =~ /\A$sub_module_spec_rx\z/o) { ...
+	if(is_module_spec("Standard::Prefix", $spec)) { ...
+	check_module_spec("Standard::Prefix", $spec);
+
+	$module_name =
+		compose_module_name("Standard::Prefix", $spec);
+
+=head1 DESCRIPTION
+
+The functions exported by this module deal with runtime handling of Perl
+modules, which are normally handled at compile time.
+
+=cut
+
+package Module::Runtime;
+
+{ use 5.006; }
+use warnings;
+use strict;
+
+use Params::Classify qw(is_string);
+
+our $VERSION = "0.007";
+
+use parent "Exporter";
+our @EXPORT_OK = qw(
+	$module_name_rx is_module_name is_valid_module_name check_module_name
+	require_module
+	use_module use_package_optimistically
+	$top_module_spec_rx $sub_module_spec_rx
+	is_module_spec is_valid_module_spec check_module_spec
+	compose_module_name
+);
+
+=head1 REGULAR EXPRESSIONS
+
+These regular expressions do not include any anchors, so to check
+whether an entire string matches a syntax item you must supply the
+anchors yourself.
+
+=over
+
+=item $module_name_rx
+
+Matches a valid Perl module name in bareword syntax.
+The rule for this, precisely, is: the string must
+consist of one or more segments separated by C<::>; each segment must
+consist of one or more identifier characters (alphanumerics plus "_");
+the first character of the string must not be a digit.  Thus "C<IO::File>",
+"C<warnings>", and "C<foo::123::x_0>" are all valid module names, whereas
+"C<IO::>" and "C<1foo::bar>" are not.
+Only ASCII characters are permitted; Perl's handling of non-ASCII
+characters in source code is inconsistent.
+C<'> separators are not permitted.
+
+=cut
+
+our $module_name_rx = qr/[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*/;
+
+=item $top_module_spec_rx
+
+Matches a module specification for use with L</compose_module_name>,
+where no prefix is being used.
+
+=cut
+
+my $qual_module_spec_rx =
+	qr#(?:/|::)[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*#;
+
+my $unqual_top_module_spec_rx =
+	qr#[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*#;
+
+our $top_module_spec_rx = qr/$qual_module_spec_rx|$unqual_top_module_spec_rx/o;
+
+=item $sub_module_spec_rx
+
+Matches a module specification for use with L</compose_module_name>,
+where a prefix is being used.
+
+=cut
+
+my $unqual_sub_module_spec_rx = qr#[0-9A-Z_a-z]+(?:(?:/|::)[0-9A-Z_a-z]+)*#;
+
+our $sub_module_spec_rx = qr/$qual_module_spec_rx|$unqual_sub_module_spec_rx/o;
+
+=back
+
+=head1 FUNCTIONS
+
+=head2 Basic module handling
+
+=over
+
+=item is_module_name(ARG)
+
+Returns a truth value indicating whether I<ARG> is a plain string
+satisfying Perl module name syntax as described for L</$module_name_rx>.
+
+=cut
+
+sub is_module_name($) { &is_string && $_[0] =~ /\A$module_name_rx\z/o }
+
+=item is_valid_module_name(ARG)
+
+Deprecated alias for L</is_module_name>.
+
+=cut
+
+*is_valid_module_name = \&is_module_name;
+
+=item check_module_name(ARG)
+
+Check whether I<ARG> is a plain string
+satisfying Perl module name syntax as described for L</$module_name_rx>.
+Return normally if it is, or C<die> if it is not.
+
+=cut
+
+sub check_module_name($) {
+	unless(&is_module_name) {
+		die +(&is_string ? "`$_[0]'" : "argument").
+			" is not a module name\n";
+	}
+}
+
+=item require_module(NAME)
+
+This is essentially the bareword form of C<require>, in runtime form.
+The I<NAME> is a string, which should be a valid module name (one or
+more C<::>-separated segments).  If it is not a valid name, the function
+C<die>s.
+
+The module specified by I<NAME> is loaded, if it hasn't been already,
+in the manner of the bareword form of C<require>.  That means that a
+search through C<@INC> is performed, and a byte-compiled form of the
+module will be used if available.
+
+The return value is as for C<require>.  That is, it is the value returned
+by the module itself if the module is loaded anew, or C<1> if the module
+was already loaded.
+
+=cut
+
+sub require_module($) {
+	&check_module_name;
+	my($name) = @_;
+	# This translation to Unix-style filename is correct regardless
+	# of platform.  This is what ck_require() in the Perl core does
+	# with a bareword, and pp_require() translates the Unix-style
+	# filename to whatever is appropriate for the real platform.
+	$name =~ s!::!/!g;
+	$name .= ".pm";
+	return require($name);
+}
+
+=back
+
+=head2 Structured module use
+
+=over
+
+=item use_module(NAME[, VERSION])
+
+This is essentially C<use> in runtime form, but without the importing
+feature (which is fundamentally a compile-time thing).  The I<NAME> is
+handled just like in C<require_module> above: it must be a module name,
+and the named module is loaded as if by the bareword form of C<require>.
+
+If a I<VERSION> is specified, the C<VERSION> method of the loaded module is
+called with the specified I<VERSION> as an argument.  This normally serves to
+ensure that the version loaded is at least the version required.  This is
+the same functionality provided by the I<VERSION> parameter of C<use>.
+
+On success, the name of the module is returned.  This is unlike
+L</require_module>, and is done so that the entire call to L</use_module>
+can be used as a class name to call a constructor, as in the example in
+the synopsis.
+
+=cut
+
+sub use_module($;$) {
+	my($name, $version) = @_;
+	require_module($name);
+	if(defined $version) {
+		$name->VERSION($version);
+	}
+	return $name;
+}
+
+=item use_package_optimistically(NAME[, VERSION])
+
+This is an analogue of L</use_module> for the situation where there is
+uncertainty as to whether a package/class is defined in its own module
+or by some other means.  It attempts to arrange for the named package to
+be available, either by loading a module or by doing nothing and hoping.
+
+If the package does not appear to already be loaded then an attempt is
+made to load the module of the same name (as if by the bareword form
+of C<require>).  If the module cannot be found then it is assumed that
+the package was actually already loaded but wasn't detected correctly,
+and no error is signalled.  That's the optimistic bit.
+
+For the purposes of this function, package existence is checked by whether
+a C<$VERSION> variable exists in the package.  If the module wasn't found,
+or if it was loaded but didn't create a C<$VERSION> variable, then such a
+variable is automatically created (with value C<undef>) so that repeated
+use of this function won't redundantly attempt to load the module.
+
+This is mostly the same operation that is performed by the L<base>
+pragma to ensure that the specified base classes are available.
+The difference is that L<base> does not allow the C<$VERSION> variable
+to remain undefined: it will set it to "C<-1, set by base.pm>" if it does
+not otherwise have a non-null value.
+
+If a I<VERSION> is specified, the C<VERSION> method of the loaded package is
+called with the specified I<VERSION> as an argument.  This normally serves
+to ensure that the version loaded is at least the version required.
+On success, the name of the package is returned.  These aspects of the
+function work just like L</use_module>.
+
+=cut
+
+sub _has_version_var($) {
+	my($name) = @_;
+	no strict "refs";
+	my $vg = ${"${name}::"}{VERSION};
+	return $vg && *{$vg}{SCALAR};
+}
+
+sub use_package_optimistically($;$) {
+	my($name, $version) = @_;
+	check_module_name($name);
+	unless(_has_version_var($name)) {
+		eval "local \$SIG{__DIE__}; require $name";
+		die $@ if $@ ne "" && $@ !~ /\ACan't locate .* at \(eval /;
+		unless(_has_version_var($name)) {
+			no strict "refs";
+			${"${name}::VERSION"} = undef;
+		}
+	}
+	$name->VERSION($version) if defined $version;
+	return $name;
+}
+
+=back
+
+=head2 Module name composition
+
+=over
+
+=item is_module_spec(PREFIX, SPEC)
+
+Returns a truth value indicating
+whether I<SPEC> is valid input for L</compose_module_name>.
+See below for what that entails.  Whether a I<PREFIX> is supplied affects
+the validity of I<SPEC>, but the exact value of the prefix is unimportant,
+so this function treats I<PREFIX> as a truth value.
+
+=cut
+
+sub is_module_spec($$) {
+	my($prefix, $spec) = @_;
+	return is_string($spec) &&
+		$spec =~ ($prefix ? qr/\A$sub_module_spec_rx\z/o :
+				    qr/\A$top_module_spec_rx\z/o);
+}
+
+=item is_valid_module_spec(PREFIX, SPEC)
+
+Deprecated alias for L</is_module_spec>.
+
+=cut
+
+*is_valid_module_spec = \&is_module_spec;
+
+=item check_module_spec(PREFIX, SPEC)
+
+Check whether I<SPEC> is valid input for L</compose_module_name>.
+Return normally if it is, or C<die> if it is not.
+
+=cut
+
+sub check_module_spec($$) {
+	unless(&is_module_spec) {
+		die +(is_string($_[1]) ? "`$_[1]'" : "argument").
+			" is not a module specification\n";
+	}
+}
+
+=item compose_module_name(PREFIX, SPEC)
+
+This function is intended to make it more convenient for a user to specify
+a Perl module name at runtime.  Users have greater need for abbreviations
+and context-sensitivity than programmers, and Perl module names get a
+little unwieldy.  I<SPEC> is what the user specifies, and this function
+translates it into a module name in standard form, which it returns.
+
+I<SPEC> has syntax approximately that of a standard module name: it
+should consist of one or more name segments, each of which consists
+of one or more identifier characters.  However, C</> is permitted as a
+separator, in addition to the standard C<::>.  The two separators are
+entirely interchangeable.
+
+Additionally, if I<PREFIX> is not C<undef> then it must be a module
+name in standard form, and it is prefixed to the user-specified name.
+The user can inhibit the prefix addition by starting I<SPEC> with a
+separator (either C</> or C<::>).
+
+=cut
+
+sub compose_module_name($$) {
+	my($prefix, $spec) = @_;
+	check_module_name($prefix) if defined $prefix;
+	&check_module_spec;
+	if($spec =~ s#\A(?:/|::)##) {
+		# OK
+	} else {
+		$spec = $prefix."::".$spec if defined $prefix;
+	}
+	$spec =~ s#/#::#g;
+	return $spec;
+}
+
+=back
+
+=head1 SEE ALSO
+
+L<base>,
+L<perlfunc/require>,
+L<perlfunc/use>
+
+=head1 AUTHOR
+
+Andrew Main (Zefram) <zefram at fysh.org>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2004, 2006, 2007, 2009, 2010
+Andrew Main (Zefram) <zefram at fysh.org>
+
+=head1 LICENSE
+
+This module is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;

Added: branches/upstream/libmodule-runtime-perl/current/t/Mod0.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/Mod0.pm?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/Mod0.pm (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/Mod0.pm Sun Apr 18 01:59:33 2010
@@ -1,0 +1,9 @@
+package t::Mod0;
+
+{ use 5.006; }
+use warnings;
+use strict;
+
+our $VERSION = 1;
+
+"t::Mod0 return";

Added: branches/upstream/libmodule-runtime-perl/current/t/Mod1.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/Mod1.pm?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/Mod1.pm (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/Mod1.pm Sun Apr 18 01:59:33 2010
@@ -1,0 +1,9 @@
+package t::Mod1;
+
+{ use 5.006; }
+use warnings;
+use strict;
+
+our $VERSION = 1;
+
+"t::Mod1 return";

Added: branches/upstream/libmodule-runtime-perl/current/t/cmn.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/cmn.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/cmn.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/cmn.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,20 @@
+use Test::More tests => 17;
+
+BEGIN { use_ok "Module::Runtime", qw(compose_module_name); }
+
+is(compose_module_name(undef, "foo"), "foo");
+is(compose_module_name(undef, "foo::bar"), "foo::bar");
+is(compose_module_name(undef, "foo/bar"), "foo::bar");
+is(compose_module_name(undef, "foo/bar/baz"), "foo::bar::baz");
+is(compose_module_name(undef, "/foo"), "foo");
+is(compose_module_name(undef, "/foo::bar"), "foo::bar");
+is(compose_module_name(undef, "::foo/bar"), "foo::bar");
+is(compose_module_name(undef, "::foo/bar/baz"), "foo::bar::baz");
+is(compose_module_name("a::b", "foo"), "a::b::foo");
+is(compose_module_name("a::b", "foo::bar"), "a::b::foo::bar");
+is(compose_module_name("a::b", "foo/bar"), "a::b::foo::bar");
+is(compose_module_name("a::b", "foo/bar/baz"), "a::b::foo::bar::baz");
+is(compose_module_name("a::b", "/foo"), "foo");
+is(compose_module_name("a::b", "/foo::bar"), "foo::bar");
+is(compose_module_name("a::b", "::foo/bar"), "foo::bar");
+is(compose_module_name("a::b", "::foo/bar/baz"), "foo::bar::baz");

Added: branches/upstream/libmodule-runtime-perl/current/t/ivmn.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/ivmn.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/ivmn.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/ivmn.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,44 @@
+use Test::More tests => 47;
+
+BEGIN { use_ok "Module::Runtime", qw(
+	$module_name_rx is_module_name is_valid_module_name check_module_name
+); }
+
+ok \&is_valid_module_name == \&is_module_name;
+
+foreach my $name (
+	undef,
+	*STDOUT,
+	\"Foo",
+	[],
+	{},
+	sub{},
+) {
+	ok(!is_module_name($name), "non-string is bad (function)");
+	eval { check_module_name($name) }; isnt $@, "";
+}
+
+foreach my $name (qw(
+	Foo
+	foo::bar
+	IO::File
+	foo::123::x_0
+	_
+)) {
+	ok(is_module_name($name), "`$name' is good (function)");
+	eval { check_module_name($name) }; is $@, "";
+	ok($name =~ /\A$module_name_rx\z/, "`$name' is good (regexp)");
+}
+
+foreach my $name (qw(
+	foo'bar
+	foo/bar
+	IO::
+	1foo::bar
+	::foo
+	foo::::bar
+)) {
+	ok(!is_module_name($name), "`$name' is bad (function)");
+	eval { check_module_name($name) }; isnt $@, "";
+	ok($name !~ /\A$module_name_rx\z/, "`$name' is bad (regexp)");
+}

Added: branches/upstream/libmodule-runtime-perl/current/t/ivms.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/ivms.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/ivms.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/ivms.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,77 @@
+use Test::More tests => 140;
+
+BEGIN { use_ok "Module::Runtime", qw(
+	$top_module_spec_rx $sub_module_spec_rx
+	is_module_spec is_valid_module_spec check_module_spec
+); }
+
+ok \&is_valid_module_spec == \&is_module_spec;
+
+foreach my $spec (
+	undef,
+	*STDOUT,
+	\"Foo",
+	[],
+	{},
+	sub{},
+) {
+	ok(!is_module_spec(0, $spec), "non-string is bad (function)");
+	eval { check_module_spec(0, $spec) }; isnt $@, "";
+	ok(!is_module_spec(1, $spec), "non-string is bad (function)");
+	eval { check_module_spec(1, $spec) }; isnt $@, "";
+}
+
+foreach my $spec (qw(
+	Foo
+	foo::bar
+	foo::123::x_0
+	foo/bar
+	foo/123::x_0
+	foo::123/x_0
+	foo/123/x_0
+	/Foo
+	/foo/bar
+	::foo/bar
+)) {
+	ok(is_module_spec(0, $spec), "`$spec' is always good (function)");
+	eval { check_module_spec(0, $spec) }; is $@, "";
+	ok($spec =~ qr/\A$top_module_spec_rx\z/,
+		"`$spec' is always good (regexp)");
+	ok(is_module_spec(1, $spec), "`$spec' is always good (function)");
+	eval { check_module_spec(1, $spec) }; is $@, "";
+	ok($spec =~ qr/\A$sub_module_spec_rx\z/,
+		"`$spec' is always good (regexp)");
+}
+
+foreach my $spec (qw(
+	foo'bar
+	IO::
+	foo::::bar
+	/foo/
+	/1foo
+	::foo::
+	::1foo
+)) {
+	ok(!is_module_spec(0, $spec), "`$spec' is always bad (function)");
+	eval { check_module_spec(0, $spec) }; isnt $@, "";
+	ok($spec !~ qr/\A$top_module_spec_rx\z/,
+		"`$spec' is always bad (regexp)");
+	ok(!is_module_spec(1, $spec), "`$spec' is always bad (function)");
+	eval { check_module_spec(1, $spec) }; isnt $@, "";
+	ok($spec !~ qr/\A$sub_module_spec_rx\z/,
+		"`$spec' is always bad (regexp)");
+}
+
+foreach my $spec (qw(
+	1foo
+	0/1
+)) {
+	ok(!is_module_spec(0, $spec), "`$spec' needs a prefix (function)");
+	eval { check_module_spec(0, $spec) }; isnt $@, "";
+	ok($spec !~ qr/\A$top_module_spec_rx\z/,
+		"`$spec' needs a prefix (regexp)");
+	ok(is_module_spec(1, $spec), "`$spec' needs a prefix (function)");
+	eval { check_module_spec(1, $spec) }; is $@, "";
+	ok($spec =~ qr/\A$sub_module_spec_rx\z/,
+		"`$spec' needs a prefix (regexp)");
+}

Added: branches/upstream/libmodule-runtime-perl/current/t/pod_cvg.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/pod_cvg.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/pod_cvg.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/pod_cvg.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,4 @@
+use Test::More;
+plan skip_all => "Test::Pod::Coverage not available"
+	unless eval "use Test::Pod::Coverage; 1";
+Test::Pod::Coverage::all_pod_coverage_ok();

Added: branches/upstream/libmodule-runtime-perl/current/t/pod_syn.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/pod_syn.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/pod_syn.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/pod_syn.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,3 @@
+use Test::More;
+plan skip_all => "Test::Pod not available" unless eval "use Test::Pod 1.00; 1";
+Test::Pod::all_pod_files_ok();

Added: branches/upstream/libmodule-runtime-perl/current/t/rm.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/rm.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/rm.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/rm.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,30 @@
+use Test::More tests => 8;
+
+BEGIN { use_ok "Module::Runtime", qw(require_module); }
+
+my($result, $err);
+
+sub test_require_module($) {
+	my($name) = @_;
+	$result = eval { require_module($name) };
+	$err = $@;
+}
+
+# a module that doesn't exist
+test_require_module("t::NotExist");
+like($err, qr/^Can't locate /);
+
+# a module that's already loaded
+test_require_module("Test::More");
+is($err, "");
+is($result, 1);
+
+# a module that we'll load now
+test_require_module("t::Mod0");
+is($err, "");
+is($result, "t::Mod0 return");
+
+# re-requiring the module that we just loaded
+test_require_module("t::Mod0");
+is($err, "");
+is($result, 1);

Added: branches/upstream/libmodule-runtime-perl/current/t/um.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/um.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/um.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/um.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,34 @@
+use Test::More tests => 9;
+
+BEGIN { use_ok "Module::Runtime", qw(use_module); }
+
+my($result, $err);
+
+sub test_use_module($;$) {
+	my($name, $version) = @_;
+	$result = eval { use_module($name, $version) };
+	$err = $@;
+}
+
+# a module that doesn't exist
+test_use_module("t::NotExist");
+like($err, qr/^Can't locate /);
+
+# a module that's already loaded
+test_use_module("Test::More");
+is($err, "");
+is($result, "Test::More");
+
+# a module that we'll load now
+test_use_module("t::Mod0");
+is($err, "");
+is($result, "t::Mod0");
+
+# successful version check
+test_use_module("Module::Runtime", 0.001);
+is($err, "");
+is($result, "Module::Runtime");
+
+# failing version check
+test_use_module("Module::Runtime", 999);
+like($err, qr/^Module::Runtime version /);

Added: branches/upstream/libmodule-runtime-perl/current/t/upo.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmodule-runtime-perl/current/t/upo.t?rev=56343&op=file
==============================================================================
--- branches/upstream/libmodule-runtime-perl/current/t/upo.t (added)
+++ branches/upstream/libmodule-runtime-perl/current/t/upo.t Sun Apr 18 01:59:33 2010
@@ -1,0 +1,45 @@
+use Test::More tests => 15;
+
+BEGIN { use_ok "Module::Runtime", qw(use_package_optimistically); }
+
+my($result, $err);
+
+sub test_use_package_optimistically($;$) {
+	my($name, $version) = @_;
+	$result = eval { use_package_optimistically($name, $version) };
+	$err = $@;
+}
+
+# a module that doesn't exist
+test_use_package_optimistically("t::NotExist");
+is $err, "";
+is $result, "t::NotExist";
+
+# a module that's already loaded
+test_use_package_optimistically("Test::More");
+is $err, "";
+is $result, "Test::More";
+
+# a module that we'll load now
+test_use_package_optimistically("t::Mod0");
+is $err, "";
+is $result, "t::Mod0";
+ok defined(${"t::Mod0::VERSION"});
+
+# successful version check
+test_use_package_optimistically("Module::Runtime", 0.001);
+is $err, "";
+is $result, "Module::Runtime";
+
+# failing version check
+test_use_package_optimistically("Module::Runtime", 999);
+like $err, qr/^Module::Runtime version /;
+
+# don't load module if $VERSION already set, although "require" will
+$t::Mod1::VERSION = undef;
+test_use_package_optimistically("t::Mod1");
+is $err, "";
+is $result, "t::Mod1";
+ok !defined($t::Mod1::VERSION);
+require t::Mod1;
+ok defined($t::Mod1::VERSION);




More information about the Pkg-perl-cvs-commits mailing list