File-ShareDir-Install-0.10/0000755000076400007640000000000012442115061013526 5ustar filfilFile-ShareDir-Install-0.10/t/0000755000076400007640000000000012442115061013771 5ustar filfilFile-ShareDir-Install-0.10/t/00_compile.t0000644000076400007640000000016512442114611016107 0ustar filfil#!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok('File::ShareDir::Install') }; File-ShareDir-Install-0.10/t/module/0000755000076400007640000000000012442115061015256 5ustar filfilFile-ShareDir-Install-0.10/t/module/.dir/0000755000076400007640000000000012442115061016112 5ustar filfilFile-ShareDir-Install-0.10/t/module/.dir/something0000644000076400007640000000003512442114611020030 0ustar filfilThu Jan 16 14:28:18 EST 2014 File-ShareDir-Install-0.10/t/module/.something0000644000076400007640000000003512442114611017252 0ustar filfilThu Jan 16 14:24:28 EST 2014 File-ShareDir-Install-0.10/t/module/deeper/0000755000076400007640000000000012442115061016522 5ustar filfilFile-ShareDir-Install-0.10/t/module/deeper/bonk0000644000076400007640000000000712442114611017373 0ustar filfildeeper File-ShareDir-Install-0.10/t/module/again0000644000076400007640000000000612442114611016254 0ustar filfilagain File-ShareDir-Install-0.10/t/module/bonk0000644000076400007640000000000512442114611016125 0ustar filfilbonk File-ShareDir-Install-0.10/t/01_pod.t0000644000076400007640000000044412442114611015242 0ustar filfil#!/usr/bin/perl use strict; use warnings; use Test::More; plan skip_all => 'these tests are for authors only' unless $ENV{AUTHOR_TESTING} or $ENV{RELEASE_TESTING}; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); File-ShareDir-Install-0.10/t/share/0000755000076400007640000000000012442115061015073 5ustar filfilFile-ShareDir-Install-0.10/t/share/.dir/0000755000076400007640000000000012442115061015727 5ustar filfilFile-ShareDir-Install-0.10/t/share/.dir/something0000644000076400007640000000003512442114611017645 0ustar filfilThu Jan 16 14:28:28 EST 2014 File-ShareDir-Install-0.10/t/share/.something0000644000076400007640000000003512442114611017067 0ustar filfilThu Jan 16 14:03:44 EST 2014 File-ShareDir-Install-0.10/t/share/honk0000644000076400007640000000000012442114611015743 0ustar filfilFile-ShareDir-Install-0.10/t/02_pod_coverage.t0000644000076400007640000000076012442114611017117 0ustar filfil#!/usr/bin/perl use strict; use warnings; use Test::More; plan skip_all => 'these tests are for authors only' unless $ENV{AUTHOR_TESTING} or $ENV{RELEASE_TESTING}; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; plan tests => 1; pod_coverage_ok( "File::ShareDir::Install", { also_private => [ ], }, "File::ShareDir::Install, ignoring private functions", ); File-ShareDir-Install-0.10/t/11_dotfile.t0000644000076400007640000000420112442114611016102 0ustar filfil#!/usr/bin/perl use strict; use warnings; use Config; use File::Path qw( rmtree ); use Test::More ( tests => 9 ); use ExtUtils::MakeMaker; my $FILE = "test-$$-Makefile"; rmtree( [ "tlib-$$", "troot-$$" ], 0, 0 ); END { $FILE and -f $FILE and unlink $FILE; rmtree( [ "tlib-$$", "troot-$$" ], 0, 0 ); } use File::ShareDir::Install; $File::ShareDir::Install::INCLUDE_DOTFILES = 1; install_share 't/share'; $File::ShareDir::Install::INCLUDE_DOTFILES = 0; $File::ShareDir::Install::INCLUDE_DOTDIRS = 1; install_share module => 'My::Test' => 't/module'; delete $ENV{PERL_MM_OPT}; # local::lib + PREFIX below will FAIL # XXX maybe we should just remove INSTALL_BASE=[^ ]+ from PERL_MM_OPT? WriteMakefile( NAME => 'File::ShareDir::Install', VERSION_FROM => 'lib/File/ShareDir/Install.pm', INST_LIB => "tlib-$$/lib", PREFIX => "troot-$$", MAKEFILE => $FILE, PREREQ_PM => {}, ($] >= 5.005 ? (ABSTRACT_FROM => 'lib/File/ShareDir/Install.pm', AUTHOR => 'Philip Gwyn ') : ()), ); sub slurp { local @ARGV = @_; local $/; local $.; <>; }; ##### ok( -f $FILE, "Created $FILE" ); my $content = slurp $FILE; ok( $content =~ m(t.share.\.something), "Shared a dotfile" ); ok( $content !~ m(t.share.\.dir), " ... but not a dotdir" ); ok( $content !~ m(t.module.dir), "Shared a dotdir " ); ok( $content !~ m(t.module.something), " ... but not a dotfile " ); ##### mysystem( $Config{make}, '-f', $FILE ); my $TOP = "tlib-$$/lib/auto/share"; ok( -f "$TOP/dist/File-ShareDir-Install/.something", "Copied a dotfile" ); ok( !-d "$TOP/dist/File-ShareDir-Install/.dir", " ... but not dotdir" ); ok( -d "$TOP/module/My-Test/.dir", "Copied a dotdir" ); ok( !-f "$TOP/module/My-Test/.something", " ... but not a dotfile" ); ##################################### sub mysystem { my $cmd = join ' ', @_; my $ret = qx($cmd 2>&1); return unless $?; die "Error running $cmd: ?=$? ret=$ret"; } ########################################################################### package MY; use File::ShareDir::Install qw(postamble); File-ShareDir-Install-0.10/t/10_makefile.t0000644000076400007640000000566612442114611016250 0ustar filfil#!/usr/bin/perl use strict; use warnings; use Config; use File::Path qw( rmtree ); use Test::More ( tests => 16 ); use ExtUtils::MakeMaker; my $FILE = "test-$$-Makefile"; rmtree( [ "tlib-$$", "troot-$$" ], 0, 0 ); END { $FILE and -f $FILE and unlink $FILE; rmtree( [ "tlib-$$", "troot-$$" ], 0, 0 ); } use File::ShareDir::Install; install_share 't/share'; install_share module => 'My::Test' => 't/module'; delete $ENV{PERL_MM_OPT}; # local::lib + PREFIX below will FAIL # XXX maybe we should just remove INSTALL_BASE=[^ ]+ from PERL_MM_OPT? WriteMakefile( NAME => 'File::ShareDir::Install', VERSION_FROM => 'lib/File/ShareDir/Install.pm', INST_LIB => "tlib-$$/lib", PREFIX => "troot-$$", MAKEFILE => $FILE, PREREQ_PM => {}, ($] >= 5.005 ? (ABSTRACT_FROM => 'lib/File/ShareDir/Install.pm', AUTHOR => 'Philip Gwyn ') : ()), ); sub slurp { local @ARGV = @_; local $/; local $.; <>; }; ##### ok( -f $FILE, "Created $FILE" ); my $content = slurp $FILE; ok( $content =~ m(t.share.honk.+share.dist...DISTNAME..honk), "Shared by dist" ); ok( $content =~ m(t.module.bonk.+share.module.My-Test.bonk), "Shared by module" ); ok( $content =~ m(t.module.again.+share.module.My-Test.again), "Shared by module again" ); ok( $content =~ m(t.module.deeper.bonk.+share.module.My-Test.deeper.bonk), "Shared by module in subdirectory" ); ok( $content !~ m(t.share.\.something), "Don't share dot files" ); ##### mysystem( $Config{make}, '-f', $FILE ); my $TOP = "tlib-$$/lib/auto/share"; ok( -f "$TOP/dist/File-ShareDir-Install/honk", "Copied to blib for dist" ); ok( -f "$TOP/module/My-Test/bonk", "Copied to blib for module" ); ok( -f "$TOP/module/My-Test/again", "Copied to blib for module again" ); ok( -f "$TOP/module/My-Test/deeper/bonk", "Copied to blib for module, in subdir" ); my $c = slurp "$TOP/module/My-Test/bonk"; is( $c, "bonk\n", "Same names" ); $c = slurp "$TOP/module/My-Test/deeper/bonk"; is( $c, "deeper\n", " ... not mixed up" ); ##### mysystem( $Config{make}, '-f', $FILE, 'install' ); unless( $content =~ m(INSTALLSITELIB = (.+)) ) { SKIP: { skip "Can't find INSTALLSITELIB in test-Makefile", 4; } } else { $TOP = "$1/auto/share"; $TOP =~ s/\$\(SITEPREFIX\)/troot-$$/; ok( -f "$TOP/dist/File-ShareDir-Install/honk", "Copied to blib for dist" ); ok( -f "$TOP/module/My-Test/bonk", "Copied to blib for module" ); ok( -f "$TOP/module/My-Test/again", "Copied to blib for module again" ); ok( -f "$TOP/module/My-Test/deeper/bonk", "Copied to blib for module, in subdir" ); } ##################################### sub mysystem { my $cmd = join ' ', @_; my $ret = qx($cmd 2>&1); return unless $?; die "Error running $cmd: ?=$? ret=$ret"; } ########################################################################### package MY; use File::ShareDir::Install qw(postamble); File-ShareDir-Install-0.10/t/12_delete.t0000644000076400007640000000375412442114611015733 0ustar filfil#!/usr/bin/perl use strict; use warnings; use Config; use File::Path qw( rmtree ); use Test::More ( tests => 7 ); use ExtUtils::MakeMaker; my $FILE = "test-$$-Makefile"; rmtree( [ "tlib-$$", "troot-$$" ], 0, 0 ); END { $FILE and -f $FILE and unlink $FILE; rmtree( [ "tlib-$$", "troot-$$" ], 0, 0 ); } use File::ShareDir::Install; install_share 't/share'; install_share module => 'My::Test' => 't/module'; delete_share 'module' => 'My::Test' => [ qw( again deeper ) ]; delete_share 'dist' => 'honk'; delete $ENV{PERL_MM_OPT}; # local::lib + PREFIX below will FAIL # XXX maybe we should just remove INSTALL_BASE=[^ ]+ from PERL_MM_OPT? WriteMakefile( NAME => 'File::ShareDir::Install', VERSION_FROM => 'lib/File/ShareDir/Install.pm', INST_LIB => "tlib-$$/lib", PREFIX => "troot-$$", MAKEFILE => $FILE, PREREQ_PM => {}, ($] >= 5.005 ? (ABSTRACT_FROM => 'lib/File/ShareDir/Install.pm', AUTHOR => 'Philip Gwyn ') : ()), ); sub slurp { local @ARGV = @_; local $/; local $.; <>; }; ##### ok( -f $FILE, "Created $FILE" ); my $content = slurp $FILE; ok( $content =~ /RM_RF.+module.My-Test.again/, "Remove a file" ); ok( $content =~ /RM_RF.+module.My-Test.deeper/, "Remove a dir" ); ok( $content =~ /RM_RF.+dist...DISTNAME..honk/, "Remove from per-dist" ) or die $content; ##### mysystem( $Config{make}, '-f', $FILE ); my $TOP = "tlib-$$/lib/auto/share"; ok( -f "$TOP/module/My-Test/bonk", "Installed this file" ); ok( !-f "$TOP/module/My-Test/again", "Removed this file" ); ok( !-d "$TOP/dist/File-ShareDir-Install/deeper", "Removed a directory" ); ##################################### sub mysystem { my $cmd = join ' ', @_; my $ret = qx($cmd 2>&1); return unless $?; die "Error running $cmd: ?=$? ret=$ret"; } ########################################################################### package MY; use File::ShareDir::Install qw(postamble); File-ShareDir-Install-0.10/Makefile.PL0000644000076400007640000000152012442114611015476 0ustar filfiluse 5.008; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'File::ShareDir::Install', VERSION_FROM => 'lib/File/ShareDir/Install.pm', # finds $VERSION LICENSE => 'perl', dist=>{COMPRESS=>'gzip -9f', EXT=>'gz'}, PREREQ_PM => { # Module::Install::Share requires this also... # (known-bad on RHEL 3, with 5.8.0) 'ExtUtils::MakeMaker' => '6.11', 'IO::Dir' => 0, 'File::Spec' => 0, }, ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/File/ShareDir/Install.pm', # retrieve abstract from module AUTHOR => 'Philip Gwyn ') : ()), ); File-ShareDir-Install-0.10/Changes0000644000076400007640000000164212442115036015026 0ustar filfilRevision history for Perl extension File::ShareDir::Install. 0.10 Dec 10 2014 - Recurse with $def in _scan_share_dir Thank you KENTNL for rt95749 0.09 Jul 7 2014 - Get rid of DB::single Thank you djerius@cpan.org - Don't do POD tests 0.08 Jan 29 2014 - Tests may now be run in parallel Thank you KENTNL@cpan.org 0.07 Jan 17 2014 - Added delete_share Thank you dmuey@cpan.org 0.06 Jan 16 2014 - Added $INCLUDE_DOTFILES and $INCLUDE_DOTDIRS Thank you sharyanto@cpan.org 0.05 Sep 3 2013 - Tweak doco and fix typos Thank you dsteinbrunner@pobox.com 0.04 Aug 25 2011 - Tweak for better error reports 0.03 Sep 9 2009 - Drop PERL_MM_OPT in test so that it passes with local::lib Thank you Peter Makholm 0.02 Jul 2 - Renamed to File::ShareDir::Install - Tweak the doco 0.01 Jul 1 - Initial release to the CPAN File-ShareDir-Install-0.10/lib/0000755000076400007640000000000012442115061014274 5ustar filfilFile-ShareDir-Install-0.10/lib/File/0000755000076400007640000000000012442115061015153 5ustar filfilFile-ShareDir-Install-0.10/lib/File/ShareDir/0000755000076400007640000000000012442115061016654 5ustar filfilFile-ShareDir-Install-0.10/lib/File/ShareDir/Install.pm0000644000076400007640000002464412442114717020641 0ustar filfilpackage File::ShareDir::Install; use 5.008; use strict; use warnings; use Carp; use File::Spec; use IO::Dir; our $VERSION = '0.10'; 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}; 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, $def ); } } } ##################################################################### # 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-Install-0.10/README0000644000076400007640000000121612442114611014406 0ustar filfilFile-ShareDir-Install version 0.01 ================================== 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. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install COPYRIGHT AND LICENCE Copyright (C) 2009-2011 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. File-ShareDir-Install-0.10/MANIFEST0000644000076400007640000000060012442115061014653 0ustar filfilChanges MANIFEST Makefile.PL README lib/File/ShareDir/Install.pm t/00_compile.t t/01_pod.t t/02_pod_coverage.t t/10_makefile.t t/11_dotfile.t t/module/.dir/something t/module/.something t/module/again t/module/bonk t/module/deeper/bonk t/share/.dir/something t/share/.something t/share/honk t/12_delete.t META.yml Module meta-data (added by MakeMaker) File-ShareDir-Install-0.10/META.yml0000664000076400007640000000067012442115061015004 0ustar filfil# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: File-ShareDir-Install version: 0.10 version_from: lib/File/ShareDir/Install.pm installdirs: site requires: ExtUtils::MakeMaker: 6.11 File::Spec: 0 IO::Dir: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30