Module-Want-0.6/000755 000765 000765 00000000000 12232515676 014046 5ustar00dmueydmuey000000 000000 Module-Want-0.6/Build.PL000644 000765 000765 00000001104 12044275477 015341 0ustar00dmueydmuey000000 000000 use strict;
use warnings;
use Module::Build;
my $builder = Module::Build->new(
module_name => 'Module::Want',
license => 'perl',
dist_author => 'Daniel Muey ',
dist_version_from => 'lib/Module/Want.pm',
requires => {
'Test::More' => 0,
'Test::Carp' => 0,
'File::Spec' => 0,
'File::Temp' => 0, # testing
'File::Path::Tiny' => 0, # testing
},
add_to_cleanup => ['Module-Want-*'],
);
$builder->create_build_script();
Module-Want-0.6/Changes000644 000765 000765 00000002220 12232514332 015321 0ustar00dmueydmuey000000 000000 Revision history for Module-Want
0.6 Fri Oct 25 11:13:39 2013
- prevent benign eval from tripping potentially fatal sig handler
0.5 Wed Oct 31 19:44:04 2012
- re-enabled strict/warnings
- make POD tests RELEASE_TESTING tests
- critic tests use RELEASE_TESTING instead of custom var
- rt 80523 POD typo
- rt 77417 add =encoding to POD
- rt 65793 Additional helper functions (get_all_use_require_in_text() doen in last version)
- get_relative_path_of_ns() alias of get_inc_key()
- normalize_ns() alias of get_clean_ns()
- get_inc_path_via_have_mod()
- search_inc_paths()
- added distname2ns() and ns2distname()
0.4 Wed Dec 21 22:53:38 2011
- add get_all_use_require_in_text()
- rt 68354 - make qw() (qw()) so tests don't emit warnings under perl 5.14
0.3 Tue Jan 11 23:10:12 2011
Added get_ns_regexp() convenience function
0.2 Thu Jul 22 22:55:15 2010
Added is_ns(), get_inc_key(), and get_clean_ns() convenience functions.
(For an entire suite if name space utilities see Module::Util and friends)
0.1 Mon May 24 23:25:16 2010
Initial release.
Module-Want-0.6/MANIFEST000644 000765 000765 00000000427 12044347472 015200 0ustar00dmueydmuey000000 000000 Build.PL
Changes
MANIFEST
Makefile.PL
README
lib/Module/Want.pm
t/00.load.t
t/perlcritic.t
t/pod-coverage.t
t/pod.t
META.yml Module meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
Module-Want-0.6/META.json000644 000765 000765 00000002036 12232515676 015470 0ustar00dmueydmuey000000 000000 {
"abstract" : "Check @INC once for modules that you want but may not have",
"author" : [
"Daniel Muey "
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.120921",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Module-Want",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"File::Path::Tiny" : "0",
"File::Spec" : "0",
"File::Temp" : "0",
"Test::Carp" : "0",
"Test::More" : "0"
}
}
},
"release_status" : "stable",
"version" : "0.6"
}
Module-Want-0.6/META.yml000644 000765 000765 00000001134 12232515676 015316 0ustar00dmueydmuey000000 000000 ---
abstract: 'Check @INC once for modules that you want but may not have'
author:
- 'Daniel Muey '
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.120921'
license: unknown
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Module-Want
no_index:
directory:
- t
- inc
requires:
File::Path::Tiny: 0
File::Spec: 0
File::Temp: 0
Test::Carp: 0
Test::More: 0
version: 0.6
Module-Want-0.6/Makefile.PL000644 000765 000765 00000001147 12044275477 016026 0ustar00dmueydmuey000000 000000 use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Module::Want',
AUTHOR => 'Daniel Muey ',
VERSION_FROM => 'lib/Module/Want.pm',
ABSTRACT_FROM => 'lib/Module/Want.pm',
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'Test::Carp' => 0,
'File::Spec' => 0,
'File::Temp' => 0, # testing
'File::Path::Tiny' => 0, # testing
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Module-Want-*' },
);
Module-Want-0.6/README000644 000765 000765 00000001130 12232514451 014707 0ustar00dmueydmuey000000 000000 Module-Want version 0.6
DOCUMENTATION
See POD for documentation.
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
Alternatively, to install with Module::Build, you can use the following commands:
perl Build.PL
./Build
./Build test
./Build install
DEPENDENCIES
See DEPENDENCIES section in POD, 'requires' key in Build.PL,
or 'PREREQ_PM' key in Makefile.PL
COPYRIGHT AND LICENCE
Copyright (C) 2010, Daniel Muey
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Module-Want-0.6/lib/000755 000765 000765 00000000000 12232515676 014614 5ustar00dmueydmuey000000 000000 Module-Want-0.6/t/000755 000765 000765 00000000000 12232515676 014311 5ustar00dmueydmuey000000 000000 Module-Want-0.6/t/00.load.t000644 000765 000765 00000023274 12044275500 015631 0ustar00dmueydmuey000000 000000 use Test::More tests => 64;
use Test::Carp;
# for search_inc_paths() tests
use File::Temp;
use File::Spec;
use File::Path::Tiny;
BEGIN {
use_ok('Module::Want');
}
diag("Testing Module::Want $Module::Want::VERSION");
ok( defined &have_mod, 'imports have_mod() ok' );
is( ref( Module::Want::get_ns_regexp() ), 'Regexp', 'get_ns_regexp() returns a regexp' );
ok( have_mod('Module::Want'), 'true on already loaded module' );
ok( have_mod('Module::Want'), 'true on already loaded module' );
ok( !have_mod('lkadjnvlkand::lvknadkjcnakjdnvjka'), 'false on unloadable module' );
ok( !have_mod('lkadjnvlkand::lvknadkjcnakjdnvjka'), 'false on unloadable module' );
does_carp_that_matches(
sub { ok( !have_mod('1invalid::ns'), 'false on invalid NS' ) },
qr/Invalid Namespace/,
);
for my $ns (qw( _what Acme Acme::XYZ Acme::ABC::DEF::X::Y::Z Acme::XYZ Acme'ABC::DEF::X::Y::Z Acme::ABC::DEF::X::Y'Z Acme::ABC::DEF'X::Y::Z Acme'ABC'DEF'X'Y'Z )) {
ok( Module::Want::is_ns($ns), "$ns is an NS" );
}
ok( !Module::Want::is_ns('1Acme'), "staring number is not an NS" );
ok( !Module::Want::is_ns(' Acme'), "space is not an NS" );
ok( Module::Want::get_clean_ns(" \n You::Can't \n") eq 'You::Can::t', 'get_clean_ns()' );
ok( Module::Want::get_inc_key('_what') eq '_what.pm', 'single level' );
ok( Module::Want::get_inc_key('Acme') eq 'Acme.pm', 'single level' );
ok( Module::Want::get_inc_key('Acme::XYZ') eq 'Acme/XYZ.pm', 'two level' );
ok( Module::Want::get_inc_key('Acme::ABC::DEF::X::Y::Z') eq 'Acme/ABC/DEF/X/Y/Z.pm', 'multi level' );
ok( Module::Want::get_inc_key('Acme::XYZ') eq 'Acme/XYZ.pm', 'two level apaost' );
ok( Module::Want::get_inc_key('Acme\'ABC::DEF::X::Y::Z') eq 'Acme/ABC/DEF/X/Y/Z.pm', 'multi level apost first' );
ok( Module::Want::get_inc_key('Acme::ABC::DEF::X::Y\'Z') eq 'Acme/ABC/DEF/X/Y/Z.pm', 'multi level apost last' );
ok( Module::Want::get_inc_key('Acme::ABC::DEF\'X::Y::Z') eq 'Acme/ABC/DEF/X/Y/Z.pm', 'multi level apost middle' );
ok( Module::Want::get_inc_key('Acme\'ABC\'DEF\'X\'Y\'Z') eq 'Acme/ABC/DEF/X/Y/Z.pm', 'multi level apost all' );
Module::Want->import( 'get_inc_key', 'is_ns' );
ok( defined &get_inc_key, 'can import get_inc_key() ok' );
ok( defined &is_ns, 'can import is_ns() ok' );
Module::Want->import( 'get_relative_path_of_ns', 'normalize_ns' );
ok( defined &get_relative_path_of_ns, 'can import get_relative_path_of_ns() ok' );
ok( defined &normalize_ns, 'can import normalize_ns() ok' );
is( \&get_relative_path_of_ns, \&get_inc_key, 'get_relative_path_of_ns() is the same as get_inc_key()' );
is( \&normalize_ns, \&Module::Want::get_clean_ns, 'get_relative_path_of_ns() is the same as get_inc_key()' );
Module::Want->import('get_inc_path_via_have_mod');
ok( defined &get_inc_path_via_have_mod, 'get_inc_path_via_have_mod() imported ok' );
ok( $INC{'Test/More.pm'}, 'Sanity check that test value is set' );
is( get_inc_path_via_have_mod('Test::More'), $INC{'Test/More.pm'}, 'get_inc_path_via_have_mod() returns the INC value' );
is( get_inc_path_via_have_mod('lkadjnvlkand::lvknadkjcnakjdnvjka'), undef, 'get_inc_path_via_have_mod() returns false on unloadable modules' );
Module::Want->import( 'distname2ns', 'ns2distname' );
ok( defined &distname2ns, 'distname2ns() imported ok' );
ok( defined &ns2distname, 'ns2distname() imported ok' );
is( ns2distname('Foo'), 'Foo', 'ns2distname() one one chunk' );
is( distname2ns('Foo'), 'Foo', 'distname2ns() one one chunk' );
is( ns2distname('Foo::Bar\'baz::Wop'), 'Foo-Bar-baz-Wop', 'ns2distname() one multi chunk (quote and colon mixed)' );
is( distname2ns('Foo-Bar-baz-Wop'), 'Foo::Bar::baz::Wop', 'distname2ns() one multi chunk' );
is( ns2distname('This is not a name space.'), undef, 'ns2distname() one invalid arg' );
is( distname2ns('This is not a distribution name.'), undef, 'distname2ns() one invalid arg' );
{
Module::Want->import('search_inc_paths');
ok( defined &search_inc_paths, 'search_inc_paths() imported ok' );
my $n = 'Foo::Bar';
my $dir = File::Temp->newdir();
local @INC = ();
my @ins;
my @pms;
for my $p (qw(a b c/d e/f/g b/Foo e/f/g/Foo)) {
my $path = File::Spec->catdir( $dir, split( m{/}, $p ) );
File::Path::Tiny::mk($path) || die "Could not setup test dir “$path”: $!";
if ( $path =~ m/Foo$/ ) {
my $pm = File::Spec->catfile( $path, 'Bar.pm' );
open my $fh, '>', $pm or die "Could not write “$pm”: $!";
print {$fh} '1;';
close $fh;
my @parts = File::Spec->splitdir($path);
pop @parts;
my $path_minus_foo = File::Spec->catdir(@parts);
push @ins, $path_minus_foo;
push @pms, $pm;
}
else {
push @INC, $path; # even though b/Foo woudl get b created we loop through b as well as b/Foo so b is added but b/Foo is not
}
}
my $first = search_inc_paths($n);
is( $first, $ins[0], 'search_inc_paths() scalar context' );
my @all = search_inc_paths($n);
is_deeply( \@all, \@ins, 'search_inc_paths() array context' );
my $abs_first = search_inc_paths( $n, 1 );
is( $abs_first, $pms[0], 'search_inc_paths() scalar context w/ abspath boolean' );
my @abs_all = search_inc_paths( $n, 1 );
is_deeply( \@abs_all, \@pms, 'search_inc_paths() array context w/ abspath boolean' );
}
is_deeply(
[
Module::Want::get_all_use_require_in_text(
q{
use No::White::Space::U;
use Some::White::Space::U;
require No::White::Space::R;
require Some::White::Space::R;
# use commentd::out;
}
)
],
[qw(No::White::Space::U Some::White::Space::U No::White::Space::R Some::White::Space::R)],
'get_all_use_require_in_text() beggining a line',
);
is_deeply(
[
Module::Want::get_all_use_require_in_text(
q{
print 1;use No::White::Space::U;
print 1; use Some::White::Space::U;
print 1;require No::White::Space::R;
print 1; require Some::White::Space::R;
# use commentd::out;
}
)
],
[qw(No::White::Space::U Some::White::Space::U No::White::Space::R Some::White::Space::R)],
'get_all_use_require_in_text() midline expression',
);
is_deeply(
[
Module::Want::get_all_use_require_in_text(
q{
use One;print 1;require Two; print 2; use Three;
require Four;print 1;use Five; print 2; require Six;
}
)
],
[qw(One Two Three Four Five Six)],
'get_all_use_require_in_text() multi line',
);
is_deeply(
[ Module::Want::get_all_use_require_in_text(q{use SemiColon; use SemiColon::Space ; use NoImport (); use Import::qw qw(a b c); use Import::paren (a b c); use Import::quote ''; }) ],
[qw(SemiColon SemiColon::Space NoImport Import::qw Import::paren Import::quote)],
'get_all_use_require_in_text() import args'
);
is_deeply(
[
Module::Want::get_all_use_require_in_text(
q{
eval("use Eval::Paren::String::U;");eval("require Eval::Paren::String::R;");
eval "use Eval::Quote::String::U;";eval "require Eval::Quote::String::R;";
eval 'use Eval::Single::String::U;';eval 'require Eval::Single::String::R;';
eval {use Eval::Block::U; };eval { require Eval::Block::R; };
}
)
],
[qw(Eval::Paren::String::U Eval::Paren::String::R Eval::Quote::String::U Eval::Quote::String::R Eval::Single::String::U Eval::Single::String::R Eval::Block::U Eval::Block::R)],
'get_all_use_require_in_text() evals'
);
is_deeply(
[
Module::Want::get_all_use_require_in_text(
q{
use
Last::Line::U;
require
Last::Line::R;
}
)
],
[qw(Last::Line::U Last::Line::R )],
'get_all_use_require_in_text() multi line statemnt'
);
SKIP: {
skip 'We are not in dev testing mode', 5 if !defined $Module::Want::DevTesting || !$Module::Want::DevTesting;
is_deeply(
[ Module::Want::_get_debugs_refs() ],
[
{
'Module::Want' => 1,
'lkadjnvlkand::lvknadkjcnakjdnvjka' => 0,
},
{
'Module::Want' => 1,
'lkadjnvlkand::lvknadkjcnakjdnvjka' => 1,
},
],
'cache and tries are as expected'
);
ok( have_mod( 'Module::Want', 1 ), 'true on already loaded module' );
ok( !have_mod( 'lkadjnvlkand::lvknadkjcnakjdnvjka', 1 ), 'false on unloadable module' );
is_deeply(
[ Module::Want::_get_debugs_refs() ],
[
{
'Module::Want' => 1,
'lkadjnvlkand::lvknadkjcnakjdnvjka' => 0,
},
{
'Module::Want' => 2,
'lkadjnvlkand::lvknadkjcnakjdnvjka' => 2,
},
],
'cache and tries are as expected'
);
Module::Want->import( "kcskcsm", "get_inc_key", "have_mod", "qsdch", "is_ns" );
is_deeply(
[ Module::Want::_get_debugs_refs() ],
[
{
'Module::Want' => 1,
'lkadjnvlkand::lvknadkjcnakjdnvjka' => 0,
'kcskcsm' => 0,
'qsdch' => 0,
},
{
'Module::Want' => 2,
'lkadjnvlkand::lvknadkjcnakjdnvjka' => 2,
'kcskcsm' => 1,
'qsdch' => 1,
},
],
'import(X,Y,Z) calls have_mod(NAME) and does not try to import functions'
);
}
Module-Want-0.6/t/perlcritic.t000644 000765 000765 00000000427 12044275500 016627 0ustar00dmueydmuey000000 000000 #!perl -T
use Test::More;
plan skip_all => 'Critic tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'};
eval 'use Test::Perl::Critic';
plan skip_all => 'Test::Perl::Critic required for testing PBP compliance' if $@;
Test::Perl::Critic::all_critic_ok();
Module-Want-0.6/t/pod-coverage.t000644 000765 000765 00000000420 12044275500 017033 0ustar00dmueydmuey000000 000000 #!perl -T
use Test::More;
plan skip_all => 'POD tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'};
eval 'use Test::Pod::Coverage 1.04';
plan skip_all => 'Test::Pod::Coverage 1.04 required for testing POD coverage' if $@;
all_pod_coverage_ok();
Module-Want-0.6/t/pod.t000644 000765 000765 00000000360 12044275500 015245 0ustar00dmueydmuey000000 000000 #!perl -T
use Test::More;
plan skip_all => 'POD tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'};
eval 'use Test::Pod 1.14';
plan skip_all => 'Test::Pod 1.14 required for testing POD' if $@;
all_pod_files_ok();
Module-Want-0.6/lib/Module/000755 000765 000765 00000000000 12232515676 016041 5ustar00dmueydmuey000000 000000 Module-Want-0.6/lib/Module/Want.pm000644 000765 000765 00000024050 12232515650 017301 0ustar00dmueydmuey000000 000000 package Module::Want;
use strict;
*normalize_ns = \&get_clean_ns; # do before warnings to prevent 'only used once' warning
*get_relative_path_of_ns = \&get_inc_key; # do before warnings to prevent 'only used once' warning
use warnings;
$Module::Want::VERSION = '0.6';
my %lookup;
# Uncomment these 3 lines and ' # $tries{$ns}++;' in have_mod() for dev testing
# $Module::Want::DevTesting = 1;
# my %tries;
# sub _get_debugs_refs { return \%lookup, \%tries }
my $ns_regexp = qr/[A-Za-z_][A-Za-z0-9_]*(?:(?:\:\:|\')[A-Za-z0-9_]+)*/;
sub get_ns_regexp { return $ns_regexp }
sub is_ns { $_[0] =~ m/\A$ns_regexp\z/ }
sub get_all_use_require_in_text {
return $_[0] =~ m/(?:^\s*|\;\s*|eval[^;]+)(?:use|require)\s+($ns_regexp)/g;
}
sub get_inc_key {
return if !is_ns( $_[0] );
# %INC keys are always unix format so no need for File::Spec
# if I've been misinformed of that fact then please let me know, thanks
my $key = $_[0] . '.pm';
$key =~ s{(?:\:\:|\')}{/}g;
return $key;
}
sub distname2ns {
my ($node) = @_;
$node =~ s/-/::/g;
my $ns = get_clean_ns($node);
return $ns if is_ns($ns);
return;
}
sub ns2distname {
my $node = get_clean_ns( $_[0] );
return if !is_ns($node);
$node =~ s/::/-/g;
return $node;
}
sub get_clean_ns {
my $dirty = $_[0];
$dirty =~ s{^\s+}{};
$dirty =~ s{\s+$}{};
$dirty =~ s{\'}{::}g;
return $dirty;
}
sub have_mod {
my ( $ns, $skip_cache ) = @_;
$skip_cache ||= 0;
if ( !is_ns($ns) ) {
require Carp;
Carp::carp('Invalid Namespace');
return;
}
if ( $skip_cache || !exists $lookup{$ns} ) {
$lookup{$ns} = 0;
# $tries{$ns}++;
local $SIG{__DIE__}; # prevent benign eval from tripping potentially fatal sig handler
eval qq{require $ns;\$lookup{\$ns}++;}; ## no critic
}
return $lookup{$ns} if $lookup{$ns};
return;
}
sub get_inc_path_via_have_mod {
my ( $ns, $skip_cache ) = @_;
return unless have_mod( $ns, $skip_cache );
return $INC{ get_inc_key($ns) };
}
sub search_inc_paths {
my ( $ns, $want_abs ) = @_;
have_mod('File::Spec') || return;
my $rel_path = File::Spec->catfile( split( m{/}, get_relative_path_of_ns($ns) ) );
my $return_first = wantarray ? 0 : 1;
my @result;
for my $path (@INC) {
my $abspath = File::Spec->rel2abs( $rel_path, $path );
if ( -f $abspath ) {
push @result, ( $want_abs ? $abspath : $path );
last if $return_first;
}
}
if (@result) {
return $result[0] if $return_first;
return @result;
}
return;
}
sub import {
shift;
my $caller = caller();
no strict 'refs'; ## no critic
*{ $caller . '::have_mod' } = \&have_mod;
for my $ns (@_) {
next if $ns eq 'have_mod';
if ( $ns eq 'is_ns' || $ns eq 'get_inc_key' || $ns eq 'get_clean_ns' || $ns eq 'get_ns_regexp' || $ns eq 'get_all_use_require_in_text' || $ns eq 'get_relative_path_of_ns' || $ns eq 'normalize_ns' || $ns eq 'get_inc_path_via_have_mod' || $ns eq 'search_inc_paths' || $ns eq 'distname2ns' || $ns eq 'ns2distname' ) {
*{ $caller . "::$ns" } = \&{$ns};
}
else {
have_mod($ns);
}
}
}
1;
__END__
=encoding utf-8
=head1 NAME
Module::Want - Check @INC once for modules that you want but may not have
=head1 VERSION
This document describes Module::Want version 0.6
=head1 SYNOPSIS
use Module::Want;
if (have_mod('Encode')) {
... use Encode::whatever ...
}
else {
... use Encode:: alternative ...
}
=head1 DESCRIPTION
Sometimes you want to lazy load a module for use in, say, a loop or function. First you do the eval-require but then realize if the module is not available it will re-search @INC each time. So then you add a lexical boolean to your eval and do the same simple logic all over the place. On and on it goes :)
This module encapsulates that logic so that have_mod() is like eval { require X; 1 } but if the module can't be loaded it will remember that fact and not look in @INC again on subsequent calls.
For example, this searches @INC for X.pm every iteration of the loop:
while( ... ) {
if (eval { require X; 1 }) {
... use X code ...
}
else {
... do X-alternative code ...
}
}
This searches @INC for X.pm once:
while( ... ) {
if (have_mod('X')) {
... use X code ...
}
else {
... do X-alternative code ...
}
}
Additionally, it will not trip the sig die handler. That prevents a benign eval from tripping a potentially fatal sig handler. (i.e. another step you'd have to do manually with the straight eval form.)
=head1 INTERFACE
import() puts have_mod() into the caller's name space.
=head2 have_mod()
Takes the name space to require() if we have not tried already.
Returns true if it could be loaded. False otherwise.
You can give it a second true argument to skip using the value from the last time it was called and re-try require()ing it.
if (!have_mod('X')) {
# do some things to try and ger X available
}
if (have_mod('X',1)) {
# sweet we have it now!
}
=head2 import()
You can use() it with a list to call have_mod() on:
use Module::Want qw(X Y Z); # calls have_mod('X'), have_mod('Y'), and have_mod('Z')
=head2 Utility functions
These aren't the real reasons for this module but they've proven useful when you're doing things that would require have_mod() so here they are:
They can all be exported thusly:
use Module::Want qw(is_ns);
For an entire suite if name space utilities see L and friends.
=head3 is_ns($ns)
Boolean of if '$ns' is a proper name space or not.
if(is_ns($ns)) {
... use $ns as a module/class name ...
}
else {
... "invalid input please try again" prompt ...
}
=head3 get_ns_regexp()
Returns a quoted Regexp that matches a name space for use in your regexes.
=head3 get_all_use_require_in_text($text)
This will return a list of all name spaces being use()d or require()d in perlish looking $text.
It will also return ones being eval()d in.
It is very simplistic (e.g. it may or may not return use/require statements that are in comments, it will match verbiage in a here doc that start w/ “use”) so if it does not fit your needs you'll need to try a L based solution (I have L on my radar that does just that.).
=head3 get_inc_key($ns)
Returns what $ns's key in %INC would be (if is_ns($ns) of course)
if (my $inc_key = get_inc_key($ns)) {
if (exists $INC{$inc_key}) {
... in %INC ...
}
else {
... not in %INC ...
}
}
%INC keys are always unix format so don't panic
If I've been misinformed of that fact then please let me know, thanks
=head4 get_relative_path_of_ns($ns)
Alias of L whose name indicates a different intent.
=head3 get_clean_ns($ns)
Takes $ns, trims leading and trailing whitespace and turns ' into ::, and returns the cleaned copy.
=head4 normalize_ns($ns)
Alias of L whose name indicates a different intent.
=head3 ns2distname($ns)
Turns the given name space into a distribution name.
e.g. Foo::Bar::Baz becomes Foo-Bar-Baz
=head3 distname2ns($distname)
Turns the given distribution name into a name space.
e.g. Foo-Bar-Baz becomes Foo::Bar::Baz
=head3 get_inc_path_via_have_mod($ns)
Return the %INC entry’s value if we have_mod($ns);
=head3 search_inc_paths($ns)
Without loading the module, search for $ns in @INC.
In scalar context returns the first path it is found in, in list context returns all paths it is found in.
my $first_path_it_is_in = search_inc_paths($ns);
my @all_paths_it_is_in = search_inc_paths($ns);
By default it returns the path it is in without the module-name part of the path. A second true argument will return the entire path.
my $abs_path_of_pm_file = search_inc_paths($ns,1);
=head1 DIAGNOSTICS
=over
=item C<< Invalid Namespace >>
The argument to have_mod() is not a name space
=back
=head1 CONFIGURATION AND ENVIRONMENT
Module::Want requires no configuration files or environment variables.
=head1 DEPENDENCIES
None.
=head1 INCOMPATIBILITIES
None reported.
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to
C, or through the web interface at
L.
=head1 AUTHOR
Daniel Muey C<< >>
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2010, Daniel Muey C<< >>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L.
=head1 DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.