App-Sqitch

 view release on metacpan or  search on metacpan

inc/Module/Build/Sqitch.pm  view on Meta::CPAN

    if ($notify) {
        $self->log_warn(q{
            #################################################################
            #                         WARNING                               #
            #                                                               #
            # As of v0.980, the location of script templates has changed.   #
            # The system-wide templates have been moved to their new        #
            # locations as described above. However, user-specific          #
            # templates have not been moved.                                #
            #                                                               #
            # Please inform all users that any custom Sqitch templates in   #
            # their ~/.sqitch/templates directories must be moved into      #
            # subdirectories using the appropriate engine name (pg, sqlite, #
            # or oracle) as follows:                                        #
            #                                                               #
            #             deploy.tmpl -> deploy/$engine.tmpl                #
            #             revert.tmpl -> revert/$engine.tmpl                #
            #             verify.tmpl -> verify/$engine.tmpl                #
            #                                                               #
            #################################################################
        } . "\n");
    }
}

sub ACTION_install {
    my ($self, @params) = @_;
    $self->depends_on('move_old_templates');
    $self->SUPER::ACTION_install(@_);
}

sub process_etc_files {
    my $self = shift;
    my $etc  = $self->_getetc;
    $self->install_path( etc => $etc );

    if (my $ddir = $self->destdir) {
        # Need to search the final destination directory.
        $etc = File::Spec->catdir($ddir, $etc);
    }

    for my $file ( @{ $self->rscan_dir( 'etc', sub { -f && !/\.\#/ } ) } ) {
        $file = $self->localize_file_path($file);

        # Remove leading `etc/` to get path relative to $etc.
        my ($vol, $dirs, $fn) = File::Spec->splitpath($file);
        my (undef, @segs) = File::Spec->splitdir($dirs);
        my $rel = File::Spec->catpath($vol, File::Spec->catdir(@segs), $fn);

        my $dest = $file;

        # Append .default if file already exists at its ultimate destination
        # or if it exists with an old name (to be moved by move_old_templates).
        if ( -e File::Spec->catfile($etc, $rel) || (
            $segs[0] eq 'templates'
                && $fn =~ /^(?:pg|sqlite)[.]tmpl$/
                && -e File::Spec->catfile($etc, 'templates', "$segs[1].tmpl")
        ) ) {
            $dest .= '.default';
        }

        $self->copy_if_modified(
            from => $file,
            to   => File::Spec->catfile( $self->blib, $dest )
        );
    }
}

sub process_pm_files {
    my $self = shift;
    my $ret  = $self->SUPER::process_pm_files(@_);
    my $pm   = File::Spec->catfile(qw(blib lib App Sqitch Config.pm));
    my $etc  = $self->installed_etcdir || $self->_getetc;

    $self->do_system(
        $self->perl, '-i.bak', '-pe',
        qq{s{my \\\$SYSTEM_DIR = undef}{my \\\$SYSTEM_DIR = q{\Q$etc\E}}},
        $pm,
    );
    unlink "$pm.bak";

    return $ret;
}

sub fix_shebang_line {
    my $self = shift;
    # Noting to do after 5.10.0.
    return $self->SUPER::fix_shebang_line(@_) if $] > 5.010000;

    # Remove -C from the shebang line.
    for my $file (@_) {
        my $FIXIN = IO::File->new($file) or die "Can't process '$file': $!";
        local $/ = "\n";
        chomp(my $line = <$FIXIN>);
        next unless $line =~ s/^\s*\#!\s*//;     # Not a shebang file.

        my ($cmd, $arg) = (split(' ', $line, 2), '');
        next unless $cmd =~ /perl/i && $arg =~ s/ -C\w+//;

        # We removed -C; write the file out.
        my $FIXOUT = IO::File->new(">$file.new")
            or die "Can't create new $file: $!\n";
        local $\;
        undef $/; # Was localized above
        print $FIXOUT "#!$cmd $arg", <$FIXIN>;
        close $FIXIN;
        close $FIXOUT;

        rename($file, "$file.bak")
            or die "Can't rename $file to $file.bak: $!";

        rename("$file.new", $file)
            or die "Can't rename $file.new to $file: $!";

        $self->delete_filetree("$file.bak")
            or $self->log_warn("Couldn't clean up $file.bak, leaving it there");
    }

    # Back at it now.
    return $self->SUPER::fix_shebang_line(@_);
}

inc/Module/Build/Sqitch.pm  view on Meta::CPAN

        local $ENV{PERL_CPANM_OPT}; # Override cpanm options.
        require Menlo::Sqitch;
        my $feat = $self->with || [];
        $feat = [$feat] unless ref $feat;
        my $app = Menlo::Sqitch->new(
            quiet          => $self->quiet,
            verbose        => $self->verbose,
            notest         => 1,
            self_contained => 1,
            skip_installed => 0,
            install_types  => [qw(requires recommends)],
            local_lib      => File::Spec->rel2abs($base),
            pod2man        => undef,
            features       => { map { $_ => 1 } @{ $feat } },
        );

        if ($self->dual_life) {
            # Force Install dual-life modules.
            $app->{argv} = [qw(
                File::Temp Scalar::Util Pod::Usage  Digest::SHA Pod::Escapes
                Pod::Find  Getopt::Long Time::HiRes File::Path  List::Util
                Encode     Pod::Simple  Time::Local parent      IO::File  if
                Term::ANSIColor
            )];
            die "Error installing modules: $@\n" if $app->run;
        }

        # Install required modules, but not Sqitch itself.
        $app->{argv} = ['.'];
        $app->{installdeps} = 1;
        die "Error installing modules: $@\n" if $app->run;

        # Remove unneeded build-time dependencies.
        die "Error removing build modules: $@\n"
            unless $app->remove_build_dependencies;
    }

    # Install Sqitch. Required to intall man pages.
    $self->depends_on('install');

    # Delete unneeded files.
    $self->delete_filetree(File::Spec->catdir($base, qw(lib perl5 Test)));
    $self->delete_filetree(File::Spec->catdir($base, qw(bin)));
    for my $file (@{ $self->rscan_dir($base, qr/[.](?:meta|packlist)$/) }) {
        $self->delete_filetree($file);
    }

    # Install sqitch script using FindBin.
    $self->_copy_findbin_script;

    # Delete empty directories.
    File::Find::finddepth(sub{rmdir},$base);
}

sub _copy_findbin_script {
    my $self = shift;
    # XXX Switch to lib/perl5.
    my $bin = $self->install_destination('script');
    my $script = File::Spec->catfile(qw(bin sqitch));
    my $dest = File::Spec->catfile($bin, 'sqitch');
    my $result = $self->copy_if_modified($script, $bin, 'flatten') or return;
    $self->fix_shebang_line($result) unless $self->is_vmsish;
    $self->_set_findbin($result);
    $self->make_executable($result);
}

sub _set_findbin {
    my ($self, $file) = @_;
    local $^I = '';
    local @ARGV = ($file);
    while (<>) {
        s{^use App::Sqitch}{use FindBin;\nuse lib "\$FindBin::RealBin/../lib/perl5";\nuse App::Sqitch};
        print;
    }
}



( run in 1.255 second using v1.01-cache-2.11-cpan-39bf76dae61 )