App-Math-Tutor
view release on metacpan or search on metacpan
inc/File-ShareDir-Install/File/ShareDir/Install.pm view on Meta::CPAN
}
#
# 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(<<CODE, ['-MExtUtils::Install']);
pm_to_blib({\@ARGV}, '$autodir')
CODE
my $files = {};
_scan_share_dir( $files, $idir, $dir, $def );
@cmds = $self->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)'
);
( run in 2.316 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )