File Coverage

blib/lib/Module/Install/Share.pm
Criterion Covered Total %
statement 18 51 35.2
branch 0 30 0.0
condition 0 12 0.0
subroutine 6 8 75.0
pod 0 1 0.0
total 24 102 23.5


line stmt bran cond sub pod time code
1             package Module::Install::Share;
2              
3 1     1   1547 use strict;
  1         6  
  1         28  
4 1     1   6 use Module::Install::Base ();
  1         2  
  1         12  
5 1     1   9 use File::Find ();
  1         2  
  1         12  
6 1     1   735 use ExtUtils::Manifest ();
  1         9375  
  1         33  
7              
8 1     1   9 use vars qw{$VERSION @ISA $ISCORE};
  1         2  
  1         74  
9             BEGIN {
10 1     1   3 $VERSION = '1.21';
11 1         26 @ISA = 'Module::Install::Base';
12 1         524 $ISCORE = 1;
13             }
14              
15             sub install_share {
16 0     0 0   my $self = shift;
17 0 0         my $dir = @_ ? pop : 'share';
18 0 0         my $type = @_ ? shift : 'dist';
19 0 0 0       unless ( defined $type and $type eq 'module' or $type eq 'dist' ) {
      0        
20 0           die "Illegal or invalid share dir type '$type'";
21             }
22 0 0 0       unless ( defined $dir and -d $dir ) {
23 0           require Carp;
24 0           Carp::croak("Illegal or missing directory install_share param: '$dir'");
25             }
26              
27             # Split by type
28 0 0         my $S = ($^O eq 'MSWin32') ? "\\" : "\/";
29              
30 0           my $root;
31 0 0         if ( $type eq 'dist' ) {
32 0 0         die "Too many parameters to install_share" if @_;
33              
34             # Set up the install
35 0           $root = "\$(INST_LIB)${S}auto${S}share${S}dist${S}\$(DISTNAME)";
36             } else {
37 0           my $module = Module::Install::_CLASS($_[0]);
38 0 0         unless ( defined $module ) {
39 0           die "Missing or invalid module name '$_[0]'";
40             }
41 0           $module =~ s/::/-/g;
42              
43 0           $root = "\$(INST_LIB)${S}auto${S}share${S}module${S}$module";
44             }
45              
46 0 0         my $manifest = -r 'MANIFEST' ? ExtUtils::Manifest::maniread() : undef;
47 0 0         my $skip_checker = $ExtUtils::Manifest::VERSION >= 1.54
48             ? ExtUtils::Manifest::maniskip()
49             : ExtUtils::Manifest::_maniskip();
50 0           my $postamble = '';
51 0 0         my $perm_dir = eval($ExtUtils::MakeMaker::VERSION) >= 6.52 ? '$(PERM_DIR)' : 755;
52             File::Find::find({
53             no_chdir => 1,
54             wanted => sub {
55 0     0     my $path = File::Spec->abs2rel($_, $dir);
56 0 0         if (-d $_) {
57 0 0         return if $skip_checker->($File::Find::name);
58 0           $postamble .=<<"END";
59             \t\$(NOECHO) \$(MKPATH) "$root${S}$path"
60             \t\$(NOECHO) \$(CHMOD) $perm_dir "$root${S}$path"
61             END
62             }
63             else {
64             return if ref $manifest
65 0 0 0       && !exists $manifest->{$File::Find::name};
66 0 0         return if $skip_checker->($File::Find::name);
67 0           $postamble .=<<"END";
68             \t\$(NOECHO) \$(CP) "$dir${S}$path" "$root${S}$path"
69             END
70             }
71             },
72 0           }, $dir);
73              
74             # Set up the install
75 0           $self->postamble(<<"END_MAKEFILE");
76             config ::
77             $postamble
78              
79             END_MAKEFILE
80              
81             # The above appears to behave incorrectly when used with old versions
82             # of ExtUtils::Install (known-bad on RHEL 3, with 5.8.0)
83             # So when we need to install a share directory, make sure we add a
84             # dependency on a moderately new version of ExtUtils::MakeMaker.
85 0           $self->build_requires( 'ExtUtils::MakeMaker' => '6.11' );
86              
87             # 99% of the time we don't want to index a shared dir
88 0           $self->no_index( directory => $dir );
89             }
90              
91             1;
92              
93             __END__
94              
95             =pod
96              
97             =head1 NAME
98              
99             Module::Install::Share - Install non-code files for use during run-time
100              
101             =head1 SYNOPSIS
102              
103             # Put everything inside ./share/ into the distribution 'auto' path
104             install_share 'share';
105              
106             # Same thing as above using the default directory name
107             install_share;
108              
109             =head1 DESCRIPTION
110              
111             As well as Perl modules and Perl binary applications, some distributions
112             need to install read-only data files to a location on the file system
113             for use at run-time.
114              
115             XML Schemas, L<YAML> data files, and L<SQLite> databases are examples of
116             the sort of things distributions might typically need to have available
117             after installation.
118              
119             C<Module::Install::Share> is a L<Module::Install> extension that provides
120             commands to allow these files to be installed to the applicable location
121             on disk.
122              
123             To locate the files after installation so they can be used inside your
124             module, see this extension's companion module L<File::ShareDir>.
125              
126             =head1 TO DO
127              
128             Currently C<install_share> installs not only the files you want, but
129             if called by the author will also copy F<.svn> and other source-control
130             directories, and other junk.
131              
132             Enhance this to copy only files under F<share> that are in the
133             F<MANIFEST>, or possibly those not in F<MANIFEST.SKIP>.
134              
135             =head1 AUTHORS
136              
137             Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
138              
139             Adam Kennedy E<lt>adamk@cpan.orgE<gt>
140              
141             =head1 SEE ALSO
142              
143             L<Module::Install>, L<File::ShareDir>
144              
145             =head1 COPYRIGHT
146              
147             Copyright 2006 Audrey Tang, Adam Kennedy.
148              
149             This program is free software; you can redistribute it and/or modify it
150             under the same terms as Perl itself.
151              
152             See L<http://www.perl.com/perl/misc/Artistic.html>
153              
154             =cut