Codebase list libfile-sharedir-install-perl / 84c11c1
[svn-inject] Installing original source of libfile-sharedir-install-perl Jonathan Yu 14 years ago
14 changed file(s) with 464 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 Revision history for Perl extension File::ShareDir::Install.
1
2 0.03 Tue Sep 9 2009
3 - Drop PERL_MM_OPT in test so that it passes with local::lib
4 Thank you Peter Makholm
5
6 0.02 Thu Jul 2
7 - Renamed to File::ShareDir::Install
8 - Tweak the doco
9
10 0.01 Wed Jul 1
11 - Initial release to the CPAN
0 Changes
1 Makefile.PL
2 MANIFEST
3 README
4 lib/File/ShareDir/Install.pm
5 t/module/again
6 t/module/deeper/bonk
7 t/module/bonk
8 t/share/honk
9 t/00_compile.t
10 t/01_pod.t
11 t/02_pod_coverage.t
12 t/10_makefile.t
13 META.yml Module meta-data (added by MakeMaker)
0 --- #YAML:1.0
1 name: File-ShareDir-Install
2 version: 0.03
3 abstract: Install shared files
4 author:
5 - Philip Gwyn <gwyn-at-cpan.org>
6 license: perl
7 distribution_type: module
8 configure_requires:
9 ExtUtils::MakeMaker: 0
10 build_requires:
11 ExtUtils::MakeMaker: 0
12 requires:
13 ExtUtils::MakeMaker: 6.11
14 File::Spec: 0
15 IO::Dir: 0
16 no_index:
17 directory:
18 - t
19 - inc
20 generated_by: ExtUtils::MakeMaker version 6.50
21 meta-spec:
22 url: http://module-build.sourceforge.net/META-spec-v1.4.html
23 version: 1.4
0 use 5.008;
1 use ExtUtils::MakeMaker;
2 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
3 # the contents of the Makefile that is written.
4 WriteMakefile(
5 NAME => 'File::ShareDir::Install',
6 VERSION_FROM => 'lib/File/ShareDir/Install.pm', # finds $VERSION
7 LICENSE => 'perl',
8 dist=>{COMPRESS=>'gzip -9f', EXT=>'gz'},
9
10 PREREQ_PM => {
11 # Module::Install::Share requires this also...
12 # (known-bad on RHEL 3, with 5.8.0)
13 'ExtUtils::MakeMaker' => '6.11',
14 'IO::Dir' => 0,
15 'File::Spec' => 0,
16 },
17 ($] >= 5.005 ? ## Add these new keywords supported since 5.005
18 (ABSTRACT_FROM => 'lib/File/ShareDir/Install.pm', # retrieve abstract from module
19 AUTHOR => 'Philip Gwyn <gwyn-at-cpan.org>') : ()),
20 );
0 File-ShareDir-Install version 0.01
1 ==================================
2
3 File::ShareDir::Install allows you to install read-only data files from a
4 distribution. It is a companion module to L<File::ShareDir>, which
5 allows you to locate these files after installation.
6
7 INSTALLATION
8
9 To install this module type the following:
10
11 perl Makefile.PL
12 make
13 make test
14 make install
15
16 COPYRIGHT AND LICENCE
17
18 Put the correct copyright and licence information here.
19
20 Copyright (C) 2009 by Philip Gwyn
21
22 This library is free software; you can redistribute it and/or modify
23 it under the same terms as Perl itself, either Perl version 5.8.8 or,
24 at your option, any later version of Perl 5 you may have available.
25
26
0 package File::ShareDir::Install;
1
2 use 5.008;
3 use strict;
4 use warnings;
5
6 use Carp;
7
8 use File::Spec;
9 use IO::Dir;
10
11 our $VERSION = '0.03';
12
13 our @DIRS;
14 our %TYPES;
15
16 require Exporter;
17
18 our @ISA = qw( Exporter);
19 our @EXPORT = qw( install_share );
20 our @EXPORT_OK = qw( postamble install_share );
21
22 #####################################################################
23 sub install_share
24 {
25 my $dir = @_ ? pop : 'share';
26 my $type = @_ ? shift : 'dist';
27 unless ( defined $type and $type eq 'module' or $type eq 'dist' ) {
28 confess "Illegal or invalid share dir type '$type'";
29 }
30 unless ( defined $dir and -d $dir ) {
31 confess "Illegal or missing directory '$dir'";
32 }
33
34 if( $type eq 'dist' and @_ ) {
35 confess "Too many parameters to share_dir";
36 }
37
38 push @DIRS, $dir;
39 $TYPES{$dir} = [ $type ];
40 if( $type eq 'module' ) {
41 my $module = _CLASS( $_[0] );
42 unless ( defined $module ) {
43 confess "Missing or invalid module name '$_[0]'";
44 }
45 push @{ $TYPES{$dir} }, $module;
46 }
47
48 }
49
50 #####################################################################
51 sub postamble
52 {
53 my $self = shift;
54
55 my @ret; # = $self->SUPER::postamble( @_ );
56 foreach my $dir ( @DIRS ) {
57 push @ret, __postamble_share_dir( $self, $dir, @{ $TYPES{ $dir } } );
58 }
59 return join "\n", @ret;
60 }
61
62 #####################################################################
63 sub __postamble_share_dir
64 {
65 my( $self, $dir, $type, $mod ) = @_;
66
67 my( $idir );
68 if ( $type eq 'dist' ) {
69 $idir = File::Spec->catdir( '$(INST_LIB)',
70 qw( auto share dist ),
71 '$(DISTNAME)'
72 );
73 } else {
74 my $module = $mod;
75 $module =~ s/::/-/g;
76 $idir = File::Spec->catdir( '$(INST_LIB)',
77 qw( auto share module ),
78 $module
79 );
80 }
81
82 my $files = {};
83 _scan_share_dir( $files, $idir, $dir );
84
85 my $autodir = '$(INST_LIB)';
86 my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
87 pm_to_blib({\@ARGV}, '$autodir')
88 CODE
89
90 my @cmds = $self->split_command( $pm_to_blib, %$files );
91
92 my $r = join '', map { "\t\$(NOECHO) $_\n" } @cmds;
93
94 # use Data::Dumper;
95 # die Dumper $files;
96 # Set up the install
97 return "config::\n$r";
98 }
99
100
101 sub _scan_share_dir
102 {
103 my( $files, $idir, $dir ) = @_;
104 my $dh = IO::Dir->new( $dir ) or die "Unable to read $dir: $!";
105 my $entry;
106 while( defined( $entry = $dh->read ) ) {
107 next if $entry =~ /^\./ or $entry =~ /(~|,v)$/;
108 my $full = File::Spec->catfile( $dir, $entry );
109 if( -f $full ) {
110 $files->{ $full } = File::Spec->catfile( $idir, $entry );
111 }
112 elsif( -d $full ) {
113 _scan_share_dir( $files, File::Spec->catdir( $idir, $entry ), $full );
114 }
115 }
116 }
117
118
119 #####################################################################
120 # Cloned from Params::Util::_CLASS
121 sub _CLASS ($) {
122 (
123 defined $_[0]
124 and
125 ! ref $_[0]
126 and
127 $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*$/s
128 ) ? $_[0] : undef;
129 }
130
131 1;
132 __END__
133
134 =head1 NAME
135
136 File::ShareDir::Install - Install shared files
137
138 =head1 SYNOPSIS
139
140 use ExtUtils::MakeMaker;
141 use File::ShareDir::Install;
142
143 install_share 'share';
144 install_share dist => 'dist-share';
145 install_share module => 'My::Module' => 'other-share';
146
147 WriteMakefile( ... ); # As you normaly would
148
149 package MY;
150 use File::ShareDir::Install qw(postamble);
151
152 =head1 DESCRIPTION
153
154 File::ShareDir::Install allows you to install read-only data files from a
155 distribution. It is a companion module to L<File::ShareDir>, which
156 allows you to locate these files after installation.
157
158 It is a port L<Module::Install::Share> to L<ExtUtils::MakeMaker> with the
159 improvement of only installing the files you want; C<.svn> and
160 other source-control junk will be ignored.
161
162 =head1 EXPORT
163
164 =head2 install_share
165
166 install_share $dir;
167 install_share dist => $dir;
168 install_share module => $module, $dir;
169
170 Causes all the files in C<$dir> and its sub-directories. to be installed
171 into a per-dist or per-module share directory. Must be called before
172 L<WriteMakefile>.
173
174 The first 2 forms are equivalent.
175
176 The files will be installed when you run C<make install>.
177
178 To locate the files after installation so they can be used inside your
179 module, see L<File::ShareDir>.
180
181 my $dir = File::ShareDir::module_dir( $module );
182
183 Note that if you make multiple calls to C<install_share> on different
184 directories that contain the same filenames, the last of these calls takes
185 precedence. In other words, if you do:
186
187 install_share 'share1';
188 install_share 'share2';
189
190 And both C<share1> and C<share2> contain a fill called C<info>, the file
191 C<share2/info> will be installed into your C<dist_dir()>.
192
193 =head2 postamble
194
195 Exported into the MY package. Only documented here if you need to write your
196 own postable.
197
198 package MY;
199 use File::ShareDir::Install;
200
201 sub postamble {
202 my $self = shift;
203 my @ret = File::ShareDir::Install::postamble( $self );
204 # ... add more things to @ret;
205 return join "\n", @ret;
206 }
207
208 =head1 SEE ALSO
209
210 L<File::ShareDir>, L<Module::Install>.
211
212 =head1 AUTHOR
213
214 Philip Gwyn, E<lt>gwyn-AT-cpan.orgE<gt>
215
216 =head1 COPYRIGHT AND LICENSE
217
218 Copyright (C) 2009 by Philip Gwyn
219
220 This library is free software; you can redistribute it and/or modify
221 it under the same terms as Perl itself, either Perl version 5.8.8 or,
222 at your option, any later version of Perl 5 you may have available.
223
224
225 =cut
0 #!/usr/bin/perl
1
2 use strict;
3 use warnings;
4
5 use Test::More tests => 1;
6 BEGIN { use_ok('File::ShareDir::Install') };
7
0 #!/usr/bin/perl
1
2 use strict;
3 use warnings;
4
5 use Test::More;
6 eval "use Test::Pod 1.00";
7 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
8
9 all_pod_files_ok();
0 #!/usr/bin/perl
1
2 use strict;
3 use warnings;
4
5 use Test::More;
6 eval "use Test::Pod::Coverage 1.00";
7 plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
8
9 plan tests => 1;
10 pod_coverage_ok(
11 "File::ShareDir::Install",
12 { also_private => [
13 # qr/^(OH|SE)_.+$/,
14 # qr/^(handler_for|instantiate|set_objectre)$/
15 ],
16 },
17 "File::ShareDir::Install, ignoring private functions",
18 );
0 #!/usr/bin/perl
1
2 use strict;
3 use warnings;
4
5 use Config;
6
7 use File::Path qw( rmtree );
8 use Test::More ( tests => 15 );
9
10 use ExtUtils::MakeMaker;
11
12 my $FILE = 'test-Makefile';
13 rmtree( [ qw( tlib troot ) ], 0, 0 );
14 END {
15 $FILE and -f $FILE and unlink $FILE;
16 rmtree( [ qw( tlib troot ) ], 0, 0 );
17 }
18
19 use File::ShareDir::Install;
20
21 install_share 't/share';
22 install_share module => 'My::Test' => 't/module';
23
24
25 delete $ENV{PERL_MM_OPT}; # local::lib + PREFIX below will FAIL
26 # XXX maybe we should just remove INSTALL_BASE=[^ ]+ from PERL_MM_OPT?
27
28 WriteMakefile(
29 NAME => 'File::ShareDir::Install',
30 VERSION_FROM => 'lib/File/ShareDir/Install.pm',
31 INST_LIB => 'tlib/lib',
32 PREFIX => 'troot',
33 MAKEFILE => $FILE,
34 PREREQ_PM => {},
35 ($] >= 5.005 ?
36 (ABSTRACT_FROM => 'lib/File/ShareDir/Install.pm',
37 AUTHOR => 'Philip Gwyn <fil@localdomain>') : ()),
38 );
39
40 sub slurp
41 {
42 local @ARGV = @_;
43 local $/;
44 local $.;
45 <>;
46 };
47
48
49 #####
50 ok( -f $FILE, "Created $FILE" );
51 my $content = slurp $FILE;
52 ok( $content =~ m(t.share.honk.+share.dist...DISTNAME..honk), "Shared by dist" );
53 ok( $content =~ m(t.module.bonk.+share.module.My-Test.bonk), "Shared by module" );
54 ok( $content =~ m(t.module.again.+share.module.My-Test.again), "Shared by module again" );
55 ok( $content =~ m(t.module.deeper.bonk.+share.module.My-Test.deeper.bonk), "Shared by module in subdirectory" );
56
57 #####
58 mysystem( $Config{make}, '-f', $FILE );
59 my $TOP = "tlib/lib/auto/share";
60 ok( -f "$TOP/dist/File-ShareDir-Install/honk", "Copied to blib for dist" );
61 ok( -f "$TOP/module/My-Test/bonk", "Copied to blib for module" );
62 ok( -f "$TOP/module/My-Test/again", "Copied to blib for module again" );
63 ok( -f "$TOP/module/My-Test/deeper/bonk", "Copied to blib for module, in subdir" );
64
65 my $c = slurp "$TOP/module/My-Test/bonk";
66 is( $c, "bonk\n", "Same names" );
67 $c = slurp "$TOP/module/My-Test/deeper/bonk";
68 is( $c, "deeper\n", " ... not mixed up" );
69
70 #####
71 mysystem( $Config{make}, '-f', $FILE, 'install' );
72 unless( $content =~ m(INSTALLSITELIB = (.+)) ) {
73 SKIP: {
74 skip "Can't find INSTALLSITELIB in test-Makefile", 4;
75 }
76 }
77 else {
78 $TOP = "$1/auto/share";
79 $TOP =~ s/\$\(SITEPREFIX\)/troot/;
80 ok( -f "$TOP/dist/File-ShareDir-Install/honk", "Copied to blib for dist" );
81 ok( -f "$TOP/module/My-Test/bonk", "Copied to blib for module" );
82 ok( -f "$TOP/module/My-Test/again", "Copied to blib for module again" );
83 ok( -f "$TOP/module/My-Test/deeper/bonk", "Copied to blib for module, in subdir" );
84 }
85
86 #####################################
87 sub mysystem
88 {
89 my $cmd = join ' ', @_;
90 my $ret = qx($cmd 2>&1);
91 return unless $?;
92 die $ret;
93 }
94
95 ###########################################################################
96 package MY;
97
98 use File::ShareDir::Install qw(postamble);
99
(New empty file)