« Dist/Zilla/Plugin/DROLSKY/License.pm
↑ Summary
Dist/Zilla/Plugin/DROLSKY/Git/CheckFor/CorrectBranch.pm »
| 1 | package Dist::Zilla::Plugin::DROLSKY::DevTools; | ||
| 2 | |||
| 3 | use v5.10; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use autodie; | ||
| 8 | use namespace::autoclean; | ||
| 9 | |||
| 10 | our $VERSION = '1.25'; | ||
| 11 | |||
| 12 | use Path::Tiny qw( path ); | ||
| 13 | |||
| 14 | use Moose; | ||
| 15 | |||
| 16 | with qw( | ||
| 17 | Dist::Zilla::Plugin::DROLSKY::Role::MaybeFileWriter | ||
| 18 | Dist::Zilla::Role::BeforeBuild | ||
| 19 | ); | ||
| 20 | |||
| 21 | sub before_build { | ||
| 22 | my $self = shift; | ||
| 23 | |||
| 24 | $self->_maybe_write_file( | ||
| 25 | 'git/setup.pl', | ||
| 26 | $self->_git_setup_pl, | ||
| 27 | 'is executable', | ||
| 28 | ); | ||
| 29 | $self->_maybe_write_file( | ||
| 30 | 'git/hooks/pre-commit.sh', | ||
| 31 | $self->_git_hooks_pre_commit_sh, | ||
| 32 | 'is executable', | ||
| 33 | ); | ||
| 34 | |||
| 35 | return; | ||
| 36 | } | ||
| 37 | |||
| 38 | my $git_setup_pl = <<'EOF'; | ||
| 39 | #!/usr/bin/env perl | ||
| 40 | |||
| 41 | use strict; | ||
| 42 | use warnings; | ||
| 43 | |||
| 44 | use Cwd qw( abs_path ); | ||
| 45 | |||
| 46 | symlink_hook('pre-commit'); | ||
| 47 | |||
| 48 | sub symlink_hook { | ||
| 49 | my $hook = shift; | ||
| 50 | |||
| 51 | my $dot = ".git/hooks/$hook"; | ||
| 52 | my $file = "git/hooks/$hook.sh"; | ||
| 53 | my $link = "../../$file"; | ||
| 54 | |||
| 55 | if ( -e $dot ) { | ||
| 56 | if ( -l $dot ) { | ||
| 57 | return if readlink $dot eq $link; | ||
| 58 | } | ||
| 59 | warn "You already have a hook at $dot!\n"; | ||
| 60 | return; | ||
| 61 | } | ||
| 62 | |||
| 63 | symlink $link, $dot | ||
| 64 | or die "Could not link $dot => $link: $!"; | ||
| 65 | } | ||
| 66 | EOF | ||
| 67 | |||
| 68 | sub _git_setup_pl {$git_setup_pl} | ||
| 69 | |||
| 70 | my $git_hooks_pre_commit_sh = <<'EOF'; | ||
| 71 | #!/bin/bash | ||
| 72 | |||
| 73 | status=0 | ||
| 74 | |||
| 75 | PRECIOUS=$(which precious) | ||
| 76 | if [[ -z $PRECIOUS ]]; then | ||
| 77 | PRECIOUS=./bin/precious | ||
| 78 | fi | ||
| 79 | |||
| 80 | "$PRECIOUS" lint -s | ||
| 81 | if (( $? != 0 )); then | ||
| 82 | status+=1 | ||
| 83 | fi | ||
| 84 | |||
| 85 | exit $status | ||
| 86 | EOF | ||
| 87 | |||
| 88 | sub _git_hooks_pre_commit_sh {$git_hooks_pre_commit_sh} | ||
| 89 | |||
| 90 | __PACKAGE__->meta->make_immutable; | ||
| 91 | |||
| 92 | 1; | ||
| 93 | |||
| 94 | # ABSTRACT: Creates scripts to install precious and git hooks | ||
| 95 | |||
| 96 | __END__ |