File-ShareDir-1.102/000755 000765 000024 00000000000 12334145750 014041 5ustar00snostaff000000 000000 File-ShareDir-1.102/Changes000644 000765 000024 00000002616 12334143600 015331 0ustar00snostaff000000 000000 Revision history for Perl extension File-ShareDir 1.02 2014-05-12 - Fix RT#95572 "necessary test files not copied into blib" Thanks to Graham Knop for fixing and Zefram for reporting - Explicitely require warnings as runtime prerequisite Thanks to Graham Knop for reporting 1.101 2014-05-10 - Reformat Changes according to CPAN::Changes::Spec - Switch to EU::MM - fix RT#95401 (Thanks, Dolmen) - Taking Maintainership (Jens Rehsack, thanks to David Golden) 1.03 2010-02-01 - Upgraded to Module::Install 1.00 1.02 2010-05-18 - Upgraded to Module::Install 0.95 - Removed Params::Util dep (MIYAGAWA) 1.01 2009-11-24 - Updating Module::Install to 0.91 - Fix typo in documentation (Thanks, ribasushi) 1.00 2009-07-17 - Everything appears ok, release prod 0.99_01 2009-07-10 - Updating tests a little - Adding the class_file function - Allow *_file to find any kind of path, not just files (hdp) - Localising $@ during evals - Implementing the new sharedir model 0.05 2006-09-04 - Upgrading to Module::Install 0.64 0.04 2006-05-09 - Made module_dir work properly under MSWin32 (ishigaki) 0.03 2006-12-27 - Upgraded to Module::Install 0.55 - Added an additional test case for a bug(sort of) in 0.54 0.02 2005-12-11 - Made dist_file work properly with Module::Install::Share 0.01 2005-12-10 - First implementation File-ShareDir-1.102/foo/000755 000765 000024 00000000000 12334145747 014632 5ustar00snostaff000000 000000 File-ShareDir-1.102/inc/000755 000765 000024 00000000000 12334145747 014620 5ustar00snostaff000000 000000 File-ShareDir-1.102/lib/000755 000765 000024 00000000000 12334145747 014615 5ustar00snostaff000000 000000 File-ShareDir-1.102/Makefile.PL000644 000765 000024 00000011020 12334143056 016002 0ustar00snostaff000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; BEGIN { eval "use File::ShareDir::Install;"; $@ and eval "use lib qw,inc/File-ShareDir-Install,; use File::ShareDir::Install;"; $@ and die $@; } use File::ShareDir::Install 0.03; install_share 'share'; # Full version install_share module => 'File::ShareDir' => 'foo'; my %RUN_DEPS = ( 'warnings' => 0, 'Carp' => 0, 'Class::Inspector' => '1.12', 'File::Spec' => '0.80', ); my %BUILD_DEPS = ( 'ExtUtils::MakeMaker' => 0, 'File::ShareDir::Install' => '0.03' ); my %TEST_DEPS = ( 'Test::More' => 0.90, ); WriteMakefile1( MIN_PERL_VERSION => '5.008001', META_ADD => { 'meta-spec' => { version => 2 }, resources => { homepage => 'https://metacpan.org/release/File-ShareDir', repository => { url => 'git@github.com:perl5-utils/File-ShareDir.git', web => 'https://github.com/perl5-utils/File-ShareDir', type => 'git', }, bugtracker => { web => 'http://rt.cpan.org/Public/Dist/Display.html?Name=File-ShareDir', mailto => 'file-sharedir@rt.cpan.org', }, }, prereqs => { develop => { requires => { 'Test::CPAN::Changes' => 0, 'Test::CheckManifest' => 0, 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0, 'Test::Pod::Spelling::CommonMistakes' => 0, }, }, configure => { requires => {%BUILD_DEPS}, recommends => { 'File::ShareDir::Install' => '0.08' } }, build => { requires => {%BUILD_DEPS} }, test => { requires => {%TEST_DEPS} }, runtime => { requires => {%RUN_DEPS}, }, }, }, NAME => 'File::ShareDir', VERSION_FROM => 'lib/File/ShareDir.pm', ABSTRACT_FROM => 'lib/File/ShareDir.pm', LICENSE => 'perl', AUTHOR => q{Adam Kennedy }, PREREQ_PM => \%RUN_DEPS, BUILD_REQUIRES => \%BUILD_DEPS, TEST_REQUIRES => \%TEST_DEPS, test => { TESTS => 't/*.t xt/*.t' }, ); sub WriteMakefile1 { # originally written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. my %params = @_; my $eumm_version = $ExtUtils::MakeMaker::VERSION; $eumm_version = eval $eumm_version; die "EXTRA_META is deprecated" if ( exists( $params{EXTRA_META} ) ); die "License not specified" if ( !exists( $params{LICENSE} ) ); if ( $params{TEST_REQUIRES} and ( $eumm_version < 6.6303 ) ) { if ( $params{BUILD_REQUIRES} ) { $params{BUILD_REQUIRES} = { %{ $params{BUILD_REQUIRES} }, %{ $params{TEST_REQUIRES} } }; } else { $params{BUILD_REQUIRES} = delete $params{TEST_REQUIRES}; } } if ( $params{BUILD_REQUIRES} and ( $eumm_version < 6.5503 ) ) { #EUMM 6.5502 has problems with BUILD_REQUIRES $params{PREREQ_PM} = { %{ $params{PREREQ_PM} || {} }, %{ $params{BUILD_REQUIRES} } }; delete $params{BUILD_REQUIRES}; } delete $params{CONFIGURE_REQUIRES} if ( $eumm_version < 6.52 ); delete $params{MIN_PERL_VERSION} if ( $eumm_version < 6.48 ); delete $params{META_MERGE} if ( $eumm_version < 6.46 ); delete $params{META_ADD}{prereqs} if ( $eumm_version < 6.58 ); delete $params{META_ADD}{'meta-spec'} if ( $eumm_version < 6.58 ); delete $params{META_ADD} if ( $eumm_version < 6.46 ); delete $params{LICENSE} if ( $eumm_version < 6.31 ); delete $params{AUTHOR} if ( $] < 5.005 ); delete $params{ABSTRACT_FROM} if ( $] < 5.005 ); delete $params{BINARY_LOCATION} if ( $] < 5.005 ); # more or less taken from Moose' Makefile.PL if ( $params{CONFLICTS} ) { my $ok = CheckConflicts(%params); exit(0) if ( $params{PREREQ_FATAL} and not $ok ); my $cpan_smoker = grep { $_ =~ m/(?:CR_SMOKER|CPAN_REPORTER|AUTOMATED_TESTING)/ } keys %ENV; unless ( $cpan_smoker || $ENV{PERL_MM_USE_DEFAULT} ) { sleep 4 unless ($ok); } delete $params{CONFLICTS}; } WriteMakefile(%params); } package MY; use File::ShareDir::Install qw(postamble); 1; File-ShareDir-1.102/MANIFEST000644 000765 000024 00000000612 12334145750 015171 0ustar00snostaff000000 000000 Changes foo/test_file.txt inc/File-ShareDir-Install/File/ShareDir/Install.pm lib/File/ShareDir.pm Makefile.PL MANIFEST This list of files share/sample.txt share/subdir/sample.txt t/01_compile.t t/02_main.t t/lib/ShareDir.pm META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) File-ShareDir-1.102/META.json000644 000765 000024 00000003570 12334145750 015467 0ustar00snostaff000000 000000 { "abstract" : "Locate per-dist and per-module shared files", "author" : [ "Adam Kennedy " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.141170", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "File-ShareDir", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0", "File::ShareDir::Install" : "0.03" } }, "configure" : { "recommends" : { "File::ShareDir::Install" : "0.08" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::ShareDir::Install" : "0.03" } }, "develop" : { "requires" : { "Test::CPAN::Changes" : "0", "Test::CheckManifest" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "Test::Pod::Spelling::CommonMistakes" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Class::Inspector" : "1.12", "File::Spec" : "0.80", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0.9" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "file-sharedir@rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=File-ShareDir" }, "homepage" : "https://metacpan.org/release/File-ShareDir", "repository" : { "type" : "git", "web" : "https://github.com/perl5-utils/File-ShareDir" } }, "version" : "1.102" } File-ShareDir-1.102/META.yml000644 000765 000024 00000001534 12334145747 015323 0ustar00snostaff000000 000000 --- abstract: 'Locate per-dist and per-module shared files' author: - 'Adam Kennedy ' build_requires: ExtUtils::MakeMaker: '0' File::ShareDir::Install: '0.03' Test::More: '0.9' configure_requires: ExtUtils::MakeMaker: '0' File::ShareDir::Install: '0.03' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.141170' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: File-ShareDir no_index: directory: - t - inc requires: Carp: '0' Class::Inspector: '1.12' File::Spec: '0.80' warnings: '0' resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=File-ShareDir homepage: https://metacpan.org/release/File-ShareDir repository: https://github.com/perl5-utils/File-ShareDir version: '1.102' File-ShareDir-1.102/share/000755 000765 000024 00000000000 12334145747 015151 5ustar00snostaff000000 000000 File-ShareDir-1.102/t/000755 000765 000024 00000000000 12334145747 014312 5ustar00snostaff000000 000000 File-ShareDir-1.102/t/01_compile.t000755 000765 000024 00000000317 12333436310 016417 0ustar00snostaff000000 000000 #!/usr/bin/perl # Compile-testing for File::ShareDir use strict; BEGIN { $| = 1; $^W = 1; } use Test::More tests => 2; ok( $] > 5.005, 'Perl version is 5.005 or newer' ); use_ok( 'File::ShareDir' ); File-ShareDir-1.102/t/02_main.t000755 000765 000024 00000006336 12333436310 015723 0ustar00snostaff000000 000000 #!/usr/bin/perl # Compile-testing for File::ShareDir use strict; BEGIN { $| = 1; $^W = 1; } use Test::More tests => 30; use File::ShareDir; sub dies { my $code = shift; my $message = shift || 'Code dies as expected'; my $rv = eval { &$code() }; ok( $@, $message ); } # Print the contents of @INC #diag("\@INC = qw{"); #foreach ( @INC ) { # diag(" $_"); #} #diag(" }"); ##################################################################### # Loading and Importing # Don't import by default ok( ! defined &dist_dir, 'dist_dir not imported by default' ); ok( ! defined &module_dir, 'module_dir not imported by default' ); ok( ! defined &dist_file, 'dist_file not imported by default' ); ok( ! defined &module_file, 'module_file not imported by default' ); ok( ! defined &class_file, 'class_file not imported by default' ); use_ok( 'File::ShareDir', ':ALL' ); # Import as needed ok( defined &dist_dir, 'dist_dir imported' ); ok( defined &module_dir, 'module_dir imported' ); ok( defined &dist_file, 'dist_file imported' ); ok( defined &module_file, 'module_file imported' ); ok( defined &class_file, 'class_file imported' ); # Allow all named functions use_ok( 'File::ShareDir', 'module_dir', 'module_file', 'dist_dir', 'dist_file', 'class_file', ); ##################################################################### # Support Methods is( File::ShareDir::_MODULE('File::ShareDir'), 'File::ShareDir', '_MODULE returns correct for known loaded module', ); is( File::ShareDir::_DIST('File-ShareDir'), 'File-ShareDir', '_DIST returns correct for known good dist', ); ##################################################################### # Module Tests my $module_dir = module_dir('File::ShareDir'); ok( $module_dir, 'Can find our own module dir' ); ok( -d $module_dir, '... and is a dir' ); ok( -r $module_dir, '... and have read permissions' ); dies( sub { module_dir() }, 'No params to module_dir dies' ); dies( sub { module_dir('') }, 'Null param to module_dir dies' ); dies( sub { module_dir('File::ShareDir::Bad') }, 'Getting module dir for known non-existanct module dies', ); my $module_file = module_file('File::ShareDir', 'test_file.txt'); ok( -f $module_file, 'module_file ok' ); ##################################################################### # Distribution Tests my $dist_dir = dist_dir('File-ShareDir'); ok( $dist_dir, 'Can find our own dist dir' ); ok( -d $dist_dir, '... and is a dir' ); ok( -r $dist_dir, '... and have read permissions' ); my $dist_file = dist_file('File-ShareDir', 'sample.txt'); ok( $dist_file, 'Can find our sample module file' ); ok( -f $dist_file, '... and is a file' ); ok( -r $dist_file, '... and have read permissions' ); # Make sure the directory in dist_dir, matches the one from dist_file # Bug found in Module::Install 0.54, fixed in 0.55 is( File::Spec->catfile($dist_dir, 'sample.txt'), $dist_file, 'dist_dir and dist_file find the same directory', ); ##################################################################### # Class Tests use t::lib::ShareDir; my $class_file = class_file('t::lib::ShareDir', 'test_file.txt'); ok( -f $class_file, 'class_file ok' ); is( $class_file, $module_file, 'class_file matches module_file for subclass' ); File-ShareDir-1.102/t/lib/000755 000765 000024 00000000000 12334145747 015060 5ustar00snostaff000000 000000 File-ShareDir-1.102/t/lib/ShareDir.pm000644 000765 000024 00000000204 12333436310 017077 0ustar00snostaff000000 000000 package t::lib::ShareDir; use strict; use vars qw{$VERSION @ISA}; BEGIN { $VERSION = '1.01'; @ISA = 'File::ShareDir'; } 1; File-ShareDir-1.102/share/sample.txt000755 000765 000024 00000000237 12333436310 017164 0ustar00snostaff000000 000000 This is a sample shared file. You should be able to locate it using the following use File::ShareDir (); module_file('File::ShareDir', 'sample.txt'); File-ShareDir-1.102/share/subdir/000755 000765 000024 00000000000 12334145747 016441 5ustar00snostaff000000 000000 File-ShareDir-1.102/share/subdir/sample.txt000755 000765 000024 00000000246 12333436310 020454 0ustar00snostaff000000 000000 This is a sample shared file. You should be able to locate it using the following use File::ShareDir (); module_file('File::ShareDir', 'subdir/sample.txt'); File-ShareDir-1.102/lib/File/000755 000765 000024 00000000000 12334145747 015474 5ustar00snostaff000000 000000 File-ShareDir-1.102/lib/File/ShareDir.pm000755 000765 000024 00000034321 12333621753 017534 0ustar00snostaff000000 000000 package File::ShareDir; =pod =head1 NAME File::ShareDir - Locate per-dist and per-module shared files =head1 SYNOPSIS use File::ShareDir ':ALL'; # Where are distribution-level shared data files kept $dir = dist_dir('File-ShareDir'); # Where are module-level shared data files kept $dir = module_dir('File::ShareDir'); # Find a specific file in our dist/module shared dir $file = dist_file( 'File-ShareDir', 'file/name.txt'); $file = module_file('File::ShareDir', 'file/name.txt'); # Like module_file, but search up the inheritance tree $file = class_file( 'Foo::Bar', 'file/name.txt' ); =head1 DESCRIPTION The intent of L is to provide a companion to L and L, modules that take a process that is well-known by advanced Perl developers but gets a little tricky, and make it more available to the larger Perl community. Quite often you want or need your Perl module (CPAN or otherwise) to have access to a large amount of read-only data that is stored on the file-system at run-time. On a linux-like system, this would be in a place such as /usr/share, however Perl runs on a wide variety of different systems, and so the use of any one location is unreliable. Perl provides a little-known method for doing this, but almost nobody is aware that it exists. As a result, module authors often go through some very strange ways to make the data available to their code. The most common of these is to dump the data out to an enormous Perl data structure and save it into the module itself. The result are enormous multi-megabyte .pm files that chew up a lot of memory needlessly. Another method is to put the data "file" after the __DATA__ compiler tag and limit yourself to access as a filehandle. The problem to solve is really quite simple. 1. Write the data files to the system at install time. 2. Know where you put them at run-time. Perl's install system creates an "auto" directory for both every distribution and for every module file. These are used by a couple of different auto-loading systems to store code fragments generated at install time, and various other modules written by the Perl "ancient masters". But the same mechanism is available to any dist or module to store any sort of data. =head2 Using Data in your Module C forms one half of a two part solution. Once the files have been installed to the correct directory, you can use C to find your files again after the installation. For the installation half of the solution, see L and its C directive. =head1 FUNCTIONS C provides four functions for locating files and directories. For greater maintainability, none of these are exported by default and you are expected to name the ones you want at use-time, or provide the C<':ALL'> tag. All of the following are equivalent. # Load but don't import, and then call directly use File::ShareDir; $dir = File::ShareDir::dist_dir('My-Dist'); # Import a single function use File::ShareDir 'dist_dir'; dist_dir('My-Dist'); # Import all the functions use File::ShareDir ':ALL'; dist_dir('My-Dist'); All of the functions will check for you that the dir/file actually exists, and that you have read permissions, or they will throw an exception. =cut use 5.005; use strict; use warnings; use Carp (); use Config (); use Exporter (); use File::Spec (); use Class::Inspector (); use vars qw{ $VERSION @ISA @EXPORT_OK %EXPORT_TAGS }; BEGIN { $VERSION = '1.102'; @ISA = qw{ Exporter }; @EXPORT_OK = qw{ dist_dir dist_file module_dir module_file class_dir class_file }; %EXPORT_TAGS = ( ALL => [ @EXPORT_OK ], ); } use constant IS_MACOS => !! ($^O eq 'MacOS'); ##################################################################### # Interface Functions =pod =head2 dist_dir # Get a distribution's shared files directory my $dir = dist_dir('My-Distribution'); The C function takes a single parameter of the name of an installed (CPAN or otherwise) distribution, and locates the shared data directory created at install time for it. Returns the directory path as a string, or dies if it cannot be located or is not readable. =cut sub dist_dir { my $dist = _DIST(shift); my $dir; # Try the new version $dir = _dist_dir_new( $dist ); return $dir if defined $dir; # Fall back to the legacy version $dir = _dist_dir_old( $dist ); return $dir if defined $dir; # Ran out of options Carp::croak("Failed to find share dir for dist '$dist'"); } sub _dist_dir_new { my $dist = shift; # Create the subpath my $path = File::Spec->catdir( 'auto', 'share', 'dist', $dist, ); # Find the full dir withing @INC foreach my $inc ( @INC ) { next unless defined $inc and ! ref $inc; my $dir = File::Spec->catdir( $inc, $path ); next unless -d $dir; unless ( -r $dir ) { Carp::croak("Found directory '$dir', but no read permissions"); } return $dir; } return undef; } sub _dist_dir_old { my $dist = shift; # Create the subpath my $path = File::Spec->catdir( 'auto', split( /-/, $dist ), ); # Find the full dir within @INC foreach my $inc ( @INC ) { next unless defined $inc and ! ref $inc; my $dir = File::Spec->catdir( $inc, $path ); next unless -d $dir; unless ( -r $dir ) { Carp::croak("Found directory '$dir', but no read permissions"); } return $dir; } return undef; } =pod =head2 module_dir # Get a module's shared files directory my $dir = module_dir('My::Module'); The C function takes a single parameter of the name of an installed (CPAN or otherwise) module, and locates the shared data directory created at install time for it. In order to find the directory, the module B be loaded when calling this function. Returns the directory path as a string, or dies if it cannot be located or is not readable. =cut sub module_dir { my $module = _MODULE(shift); my $dir; # Try the new version $dir = _module_dir_new( $module ); return $dir if defined $dir; # Fall back to the legacy version return _module_dir_old( $module ); } sub _module_dir_new { my $module = shift; # Create the subpath my $path = File::Spec->catdir( 'auto', 'share', 'module', _module_subdir( $module ), ); # Find the full dir withing @INC foreach my $inc ( @INC ) { next unless defined $inc and ! ref $inc; my $dir = File::Spec->catdir( $inc, $path ); next unless -d $dir; unless ( -r $dir ) { Carp::croak("Found directory '$dir', but no read permissions"); } return $dir; } return undef; } sub _module_dir_old { my $module = shift; my $short = Class::Inspector->filename($module); my $long = Class::Inspector->loaded_filename($module); $short =~ tr{/}{:} if IS_MACOS; substr( $short, -3, 3, '' ); $long =~ m/^(.*)\Q$short\E\.pm\z/s or die("Failed to find base dir"); my $dir = File::Spec->catdir( "$1", 'auto', $short ); unless ( -d $dir ) { Carp::croak("Directory '$dir', does not exist"); } unless ( -r $dir ) { Carp::croak("Directory '$dir', no read permissions"); } return $dir; } =pod =head2 dist_file # Find a file in our distribution shared dir my $dir = dist_file('My-Distribution', 'file/name.txt'); The C function takes two params of the distribution name and file name, locates the dist dir, and then finds the file within it, verifying that the file actually exists, and that it is readable. The filename should be a relative path in the format of your local filesystem. It will simply added to the directory using L's C method. Returns the file path as a string, or dies if the file or the dist's directory cannot be located, or the file is not readable. =cut sub dist_file { my $dist = _DIST(shift); my $file = _FILE(shift); # Try the new version first my $path = _dist_file_new( $dist, $file ); return $path if defined $path; # Hand off to the legacy version return _dist_file_old( $dist, $file );; } sub _dist_file_new { my $dist = shift; my $file = shift; # If it exists, what should the path be my $dir = _dist_dir_new( $dist ); my $path = File::Spec->catfile( $dir, $file ); # Does the file exist return undef unless -e $path; unless ( -f $path ) { Carp::croak("Found dist_file '$path', but not a file"); } unless ( -r $path ) { Carp::croak("File '$path', no read permissions"); } return $path; } sub _dist_file_old { my $dist = shift; my $file = shift; # Create the subpath my $path = File::Spec->catfile( 'auto', split( /-/, $dist ), $file, ); # Find the full dir withing @INC foreach my $inc ( @INC ) { next unless defined $inc and ! ref $inc; my $full = File::Spec->catdir( $inc, $path ); next unless -e $full; unless ( -r $full ) { Carp::croak("Directory '$full', no read permissions"); } return $full; } # Couldn't find it Carp::croak("Failed to find shared file '$file' for dist '$dist'"); } =pod =head2 module_file # Find a file in our module shared dir my $dir = module_file('My::Module', 'file/name.txt'); The C function takes two params of the module name and file name. It locates the module dir, and then finds the file within it, verifying that the file actually exists, and that it is readable. In order to find the directory, the module B be loaded when calling this function. The filename should be a relative path in the format of your local filesystem. It will simply added to the directory using L's C method. Returns the file path as a string, or dies if the file or the dist's directory cannot be located, or the file is not readable. =cut sub module_file { my $module = _MODULE(shift); my $file = _FILE(shift); my $dir = module_dir($module); my $path = File::Spec->catfile($dir, $file); unless ( -e $path ) { Carp::croak("File '$file' does not exist in module dir"); } unless ( -r $path ) { Carp::croak("File '$file' cannot be read, no read permissions"); } $path; } =pod =head2 class_file # Find a file in our module shared dir, or in our parent class my $dir = class_file('My::Module', 'file/name.txt'); The C function takes two params of the module name and file name. It locates the module dir, and then finds the file within it, verifying that the file actually exists, and that it is readable. In order to find the directory, the module B be loaded when calling this function. The filename should be a relative path in the format of your local filesystem. It will simply added to the directory using L's C method. If the file is NOT found for that module, C will scan up the module's @ISA tree, looking for the file in all of the parent classes. This allows you to, in effect, "subclass" shared files. Returns the file path as a string, or dies if the file or the dist's directory cannot be located, or the file is not readable. =cut sub class_file { my $module = _MODULE(shift); my $file = _FILE(shift); # Get the super path ( not including UNIVERSAL ) # Rather than using Class::ISA, we'll use an inlined version # that implements the same basic algorithm. my @path = (); my @queue = ( $module ); my %seen = ( $module => 1 ); while ( my $cl = shift @queue ) { push @path, $cl; no strict 'refs'; unshift @queue, grep { ! $seen{$_}++ } map { s/^::/main::/; s/\'/::/g; $_ } ( @{"${cl}::ISA"} ); } # Search up the path foreach my $class ( @path ) { local $@; my $dir = eval { module_dir($class); }; next if $@; my $path = File::Spec->catfile($dir, $file); unless ( -e $path ) { next; } unless ( -r $path ) { Carp::croak("File '$file' cannot be read, no read permissions"); } return $path; } Carp::croak("File '$file' does not exist in class or parent shared files"); } ##################################################################### # Support Functions sub _module_subdir { my $module = shift; $module =~ s/::/-/g; return $module; } sub _dist_packfile { my $module = shift; my @dirs = grep { -e } ( $Config::Config{archlibexp}, $Config::Config{sitearchexp} ); my $file = File::Spec->catfile( 'auto', split( /::/, $module), '.packlist', ); foreach my $dir ( @dirs ) { my $path = File::Spec->catfile( $dir, $file ); next unless -f $path; # Load the file my $packlist = ExtUtils::Packlist->new($path); unless ( $packlist ) { die "Failed to load .packlist file for $module"; } die "CODE INCOMPLETE"; } die "CODE INCOMPLETE"; } # Inlined from Params::Util pure perl version sub _CLASS { (defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s) ? $_[0] : undef; } # Maintainer note: The following private functions are used by # File::ShareDir::PAR. (It has to or else it would have to copy&fork) # So if you significantly change or even remove them, please # notify the File::ShareDir::PAR maintainer(s). Thank you! # Matches a valid distribution name ### This is a total guess at this point sub _DIST { if ( defined $_[0] and ! ref $_[0] and $_[0] =~ /^[a-z0-9+_-]+$/is ) { return shift; } Carp::croak("Not a valid distribution name"); } # A valid and loaded module name sub _MODULE { my $module = _CLASS(shift) or Carp::croak("Not a valid module name"); if ( Class::Inspector->loaded($module) ) { return $module; } Carp::croak("Module '$module' is not loaded"); } # A valid file name sub _FILE { my $file = shift; unless ( defined $file and ! ref $file and length $file ) { Carp::croak("Did not pass a file name"); } if ( File::Spec->file_name_is_absolute($file) ) { Carp::croak("Cannot use absolute file name '$file'"); } $file; } 1; =pod =head1 SUPPORT Bugs should always be submitted via the CPAN bug tracker L For other issues, contact the maintainer. =head1 AUTHOR Adam Kennedy Eadamk@cpan.orgE =head1 SEE ALSO L, L, L, L, L, L =head1 COPYRIGHT Copyright 2005 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. =cut File-ShareDir-1.102/inc/File-ShareDir-Install/000755 000765 000024 00000000000 12334145747 020602 5ustar00snostaff000000 000000 File-ShareDir-1.102/inc/File-ShareDir-Install/File/000755 000765 000024 00000000000 12334145747 021461 5ustar00snostaff000000 000000 File-ShareDir-1.102/inc/File-ShareDir-Install/File/ShareDir/000755 000765 000024 00000000000 12334145747 023162 5ustar00snostaff000000 000000 File-ShareDir-1.102/inc/File-ShareDir-Install/File/ShareDir/Install.pm000444 000765 000024 00000024663 12333440073 025124 0ustar00snostaff000000 000000 package File::ShareDir::Install; use 5.008; use strict; use warnings; use Carp; use File::Spec; use IO::Dir; our $VERSION = '0.08'; our @DIRS; our %ALREADY; require Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( install_share delete_share ); our @EXPORT_OK = qw( postamble install_share delete_share ); our $INCLUDE_DOTFILES = 0; our $INCLUDE_DOTDIRS = 0; ##################################################################### sub install_share { my $dir = @_ ? pop : 'share'; my $type = @_ ? shift : 'dist'; unless ( defined $type and ( $type =~ /^(module|dist)$/ ) ) { confess "Illegal or invalid share dir type '$type'"; } if( $type eq 'dist' and @_ ) { confess "Too many parameters to install_share"; } my $def = _mk_def( $type ); _add_module( $def, $_[0] ); _add_dir( $def, $dir ); } ##################################################################### sub delete_share { my $dir = @_ ? pop : ''; my $type = @_ ? shift : 'dist'; unless ( defined $type and ( $type =~ /^(module|dist)$/ ) ) { confess "Illegal or invalid share dir type '$type'"; } if( $type eq 'dist' and @_ ) { confess "Too many parameters to delete_share"; } my $def = _mk_def( "delete-$type" ); _add_module( $def, $_[0] ); _add_dir( $def, $dir ); } # # Build a task definition sub _mk_def { my( $type ) = @_; return { type=>$type, dotfiles => $INCLUDE_DOTFILES, dotdirs => $INCLUDE_DOTDIRS }; } # # Add the module to a task definition sub _add_module { my( $def, $class ) = @_; if( $def->{type} =~ /module$/ ) { my $module = _CLASS( $class ); unless ( defined $module ) { confess "Missing or invalid module name '$_[0]'"; } $def->{module} = $module; } } # # Add directories to a task definition # Save the definition sub _add_dir { my( $def, $dir ) = @_; $dir = [ $dir ] unless ref $dir; my $del = 0; $del = 1 if $def->{type} =~ /^delete-/; foreach my $d ( @$dir ) { unless ( $del or (defined $d and -d $d) ) { confess "Illegal or missing directory '$d'"; } if( not $del and $ALREADY{ $d }++ ) { confess "Directory '$d' is already being installed"; } push @DIRS, { %$def }; $DIRS[-1]{dir} = $d; } } ##################################################################### # Build the postamble section sub postamble { my $self = shift; my @ret; # = $self->SUPER::postamble( @_ ); foreach my $def ( @DIRS ) { push @ret, __postamble_share_dir( $self, $def ); } return join "\n", @ret; } ##################################################################### sub __postamble_share_dir { my( $self, $def ) = @_; my $dir = $def->{dir}; $DB::single = 1; my( $idir ); if( $def->{type} eq 'delete-dist' ) { $idir = File::Spec->catdir( _dist_dir(), $dir ); } elsif( $def->{type} eq 'delete-module' ) { $idir = File::Spec->catdir( _module_dir( $def ), $dir ); } elsif ( $def->{type} eq 'dist' ) { $idir = _dist_dir(); } else { # delete-share and share $idir = _module_dir( $def ); } my @cmds; if( $def->{type} =~ /^delete-/ ) { @cmds = "\$(RM_RF) $idir"; } else { my $autodir = '$(INST_LIB)'; my $pm_to_blib = $self->oneliner(<split_command( $pm_to_blib, %$files ); } my $r = join '', map { "\t\$(NOECHO) $_\n" } @cmds; # use Data::Dumper; # die Dumper $files; # Set up the install return "config::\n$r"; } # Get the per-dist install directory. # We depend on the Makefile for most of the info sub _dist_dir { return File::Spec->catdir( '$(INST_LIB)', qw( auto share dist ), '$(DISTNAME)' ); } # Get the per-module install directory # We depend on the Makefile for most of the info sub _module_dir { my( $def ) = @_; my $module = $def->{module}; $module =~ s/::/-/g; return File::Spec->catdir( '$(INST_LIB)', qw( auto share module ), $module ); } sub _scan_share_dir { my( $files, $idir, $dir, $def ) = @_; my $dh = IO::Dir->new( $dir ) or die "Unable to read $dir: $!"; my $entry; while( defined( $entry = $dh->read ) ) { next if $entry =~ /(~|,v|#)$/; my $full = File::Spec->catfile( $dir, $entry ); if( -f $full ) { next if not $def->{dotfiles} and $entry =~ /^\./; $files->{ $full } = File::Spec->catfile( $idir, $entry ); } elsif( -d $full ) { if( $def->{dotdirs} ) { next if $entry eq '.' or $entry eq '..' or $entry =~ /^\.(svn|git|cvs)$/; } else { next if $entry =~ /^\./; } _scan_share_dir( $files, File::Spec->catdir( $idir, $entry ), $full ); } } } ##################################################################### # Cloned from Params::Util::_CLASS sub _CLASS ($) { ( defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*$/s ) ? $_[0] : undef; } 1; __END__ =head1 NAME File::ShareDir::Install - Install shared files =head1 SYNOPSIS use ExtUtils::MakeMaker; use File::ShareDir::Install; install_share 'share'; install_share dist => 'dist-share'; install_share module => 'My::Module' => 'other-share'; WriteMakefile( ... ); # As you normaly would package MY; use File::ShareDir::Install qw(postamble); =head1 DESCRIPTION File::ShareDir::Install allows you to install read-only data files from a distribution. It is a companion module to L, which allows you to locate these files after installation. It is a port of L to L with the improvement of only installing the files you want; C<.svn>, C<.git> and other source-control junk will be ignored. Please note that this module installs read-only data files; empty directories will be ignored. =head1 EXPORT =head2 install_share install_share $dir; install_share dist => $dir; install_share module => $module, $dir; Causes all the files in C<$dir> and its sub-directories to be installed into a per-dist or per-module share directory. Must be called before L. The first 2 forms are equivalent; the files are installed in a per-distribution directory. For example C. The name of that directory can be recovered with L. The last form installs files in a per-module directory. For example C. The name of that directory can be recovered with L. The parameter C<$dir> may be an array of directories. The files will be installed when you run C. However, the list of files to install is generated when Makefile.PL is run. Note that if you make multiple calls to C on different directories that contain the same filenames, the last of these calls takes precedence. In other words, if you do: install_share 'share1'; install_share 'share2'; And both C and C contain a file called C, the file C will be installed into your C. =head2 delete_share delete_share $list; delete_share dist => $list; delete_share module => $module, $list; Remove previously installed files or directories. Unlike L, the last parameter is a list of files or directories that were previously installed. These files and directories will be deleted when you run C. The parameter C<$list> may be an array of files or directories. Deletion happens in-order along with installation. This means that you may delete all previously installed files by putting the following at the top of your Makefile.PL. delete_share '.'; You can also selectively remove some files from installation. install_share 'some-dir'; if( ... ) { delete_share 'not-this-file.rc'; } =head2 postamble This function must be exported into the MY package. You will normaly do this with the following. package MY; use File::ShareDir::Install qw( postamble ); If you need to overload postamble, use the following. package MY; use File::ShareDir::Install; sub postamble { my $self = shift; my @ret = File::ShareDir::Install::postamble( $self ); # ... add more things to @ret; return join "\n", @ret; } =head1 CONFIGURATION 2 variables control the handling of dot-files and dot-directories. A dot-file has a filename that starts with a period (.). For example C<.htaccess>. A dot-directory (or dot-dir) is a directory that starts with a period (.). For example C<.config/>. Not all filesystems support the use of dot-files. =head2 $INCLUDE_DOTFILES If set to a true value, dot-files will be copied. Default is false. =head2 $INCLUDE_DOTDIRS If set to a true value, the files inside dot-directories will be copied. Known version control directories are still ignored. Default is false. =head2 Note These variables only influence subsequent calls to C. This allows you to control the behaviour for each directory. For example: $INCLUDE_DOTDIRS = 1; install_share 'share1'; $INCLUDE_DOTFILES = 1; $INCLUDE_DOTDIRS = 0; install_share 'share2'; The directory C will have files in its dot-directories installed, but not dot-files. The directory C will have files in its dot-files installed, but dot-directories will be ignored. =head1 SEE ALSO L, L. =head1 AUTHOR Philip Gwyn, Egwyn-AT-cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2009-2014 by Philip Gwyn This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. =cut File-ShareDir-1.102/foo/test_file.txt000644 000765 000024 00000000022 12333442550 017332 0ustar00snostaff000000 000000 Another test file