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   1124 use strict;
  1         2  
  1         25  
4 1     1   4 use Module::Install::Base ();
  1         2  
  1         10  
5 1     1   4 use File::Find ();
  1         1  
  1         11  
6 1     1   472 use ExtUtils::Manifest ();
  1         7387  
  1         39  
7              
8 1     1   7 use vars qw{$VERSION @ISA $ISCORE};
  1         2  
  1         61  
9             BEGIN {
10 1     1   3 $VERSION = '1.19';
11 1         24 @ISA = 'Module::Install::Base';
12 1         405 $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__