| 1 | #--------------------------------------------------------------------- | ||||||||||
| 2 | package Dist::Zilla::Plugin::ArchiveRelease; | ||||||||||
| 3 | # | ||||||||||
| 4 | # Copyright 2010 Christopher J. Madsen | ||||||||||
| 5 | # | ||||||||||
| 6 | # Author: Christopher J. Madsen <perl@cjmweb.net> | ||||||||||
| 7 | # Created: 6 Mar 2010 | ||||||||||
| 8 | # | ||||||||||
| 9 | # This program is free software; you can redistribute it and/or modify | ||||||||||
| 10 | # it under the same terms as Perl itself. | ||||||||||
| 11 | # | ||||||||||
| 12 | # This program is distributed in the hope that it will be useful, | ||||||||||
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the | ||||||||||
| 15 | # GNU General Public License or the Artistic License for more details. | ||||||||||
| 16 | # | ||||||||||
| 17 | # ABSTRACT: Move the release tarball to an archive directory | ||||||||||
| 18 | #--------------------------------------------------------------------- | ||||||||||
| 19 | |||||||||||
| 20 | 2 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | our $VERSION = '6.000'; | |||||||||
| 22 | # This file is part of Dist-Zilla-Plugins-CJM 6.000 (December 17, 2017) | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 2 | with 'Dist::Zilla::Role::BeforeRelease'; | |||||||||
| 27 | 2 | with 'Dist::Zilla::Role::Releaser'; | |||||||||
| 28 | 2 | with 'Dist::Zilla::Role::FilePruner'; | |||||||||
| 29 | |||||||||||
| 30 | 2 | ▶ | use Path::Tiny (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | #--------------------------------------------------------------------- | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 2 | has _directory => ( | |||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | isa => 'Str', | ||||||||||
| 37 | default => 'releases', | ||||||||||
| 38 | init_arg => 'directory', | ||||||||||
| 39 | writer => '_set_directory', | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | sub directory | ||||||||||
| 43 | 6 | ▶ | { | ||||||||
|
Subroutine
directory: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 44 | 6 | my $self = shift; | |||||||||
| 45 | |||||||||||
| 46 | 6 | my $dir = $self->_directory; | |||||||||
| 47 | |||||||||||
| 48 | # Convert ~ to home directory: | ||||||||||
| 49 | 6 | ▶ | if ($dir =~ /^~/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 1 | require File::HomeDir; | |||||||||
| 51 | 1 | File::HomeDir->VERSION(0.81); | |||||||||
| 52 | |||||||||||
| 53 | 0 | $dir =~ s/^~(\w+)/ File::HomeDir->users_home("$1") /e; | |||||||||
| 54 | 1 | $dir =~ s/^~/ File::HomeDir->my_home /e; | |||||||||
| 55 | |||||||||||
| 56 | 1 | $self->_set_directory($dir); | |||||||||
| 57 | } # end if $dir begins with ~ | ||||||||||
| 58 | |||||||||||
| 59 | 6 | Path::Tiny::path($dir)->absolute($self->zilla->root); | |||||||||
| 60 | } # end directory | ||||||||||
| 61 | |||||||||||
| 62 | #--------------------------------------------------------------------- | ||||||||||
| 63 | # Format a path for display: | ||||||||||
| 64 | |||||||||||
| 65 | sub pretty_path | ||||||||||
| 66 | 1 | ▶ | { | ||||||||
|
Subroutine
pretty_path: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 67 | 1 | my ($self, $path) = @_; | |||||||||
| 68 | |||||||||||
| 69 | 1 | my $root = $self->zilla->root; | |||||||||
| 70 | |||||||||||
| 71 | 1 | ▶ | $path = $path->relative($root) if $root->subsumes($path); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | 1 | "$path"; | |||||||||
| 74 | } # end pretty_path | ||||||||||
| 75 | |||||||||||
| 76 | #--------------------------------------------------------------------- | ||||||||||
| 77 | # Don't distribute previously archived releases: | ||||||||||
| 78 | |||||||||||
| 79 | sub prune_files | ||||||||||
| 80 | 3 | ▶ | { | ||||||||
|
Subroutine
prune_files: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 81 | 3 | my $self = shift; | |||||||||
| 82 | |||||||||||
| 83 | 3 | my $root = $self->zilla->root; | |||||||||
| 84 | 3 | my $dir = $self->directory; | |||||||||
| 85 | |||||||||||
| 86 | 3 | ▶ | if ($root->subsumes($dir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 3 | $dir = $dir->relative($root); | |||||||||
| 88 | 3 | my $files = $self->zilla->files; | |||||||||
| 89 | |||||||||||
| 90 | 3 | @$files = grep { not $dir->subsumes($_->name) } @$files; | |||||||||
| 91 | } # end if archive directory is inside root | ||||||||||
| 92 | |||||||||||
| 93 | 3 | return; | |||||||||
| 94 | } # end prune_files | ||||||||||
| 95 | |||||||||||
| 96 | #--------------------------------------------------------------------- | ||||||||||
| 97 | sub before_release | ||||||||||
| 98 | 1 | ▶ | { | ||||||||
|
Subroutine
before_release: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||
| 99 | 1 | my ($self, $tgz) = @_; | |||||||||
| 100 | |||||||||||
| 101 | 1 | my $dir = $self->directory; | |||||||||
| 102 | |||||||||||
| 103 | # If the directory doesn't exist, create it: | ||||||||||
| 104 | 1 | ▶ | unless (-d $dir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | my $dirR = $self->pretty_path($dir); | |||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | mkdir $dir or $self->log_fatal("Unable to create directory $dirR: $!"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | $self->log("Created directory $dirR"); | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | # If the tarball has already been archived, abort: | ||||||||||
| 112 | 1 | my $file = $dir->child($tgz->basename); | |||||||||
| 113 | |||||||||||
| 114 | 1 | ▶ | $self->log_fatal($self->pretty_path($file) . " already exists") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | if -e $file; | ||||||||||
| 116 | } # end before_release | ||||||||||
| 117 | |||||||||||
| 118 | #--------------------------------------------------------------------- | ||||||||||
| 119 | # Main entry point: | ||||||||||
| 120 | |||||||||||
| 121 | sub release | ||||||||||
| 122 | 1 | ▶ | { | ||||||||
|
Subroutine
release: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 123 | 1 | my ($self, $tgz) = @_; | |||||||||
| 124 | |||||||||||
| 125 | 1 | chmod(0444, $tgz); | |||||||||
| 126 | |||||||||||
| 127 | 1 | my $dest = $self->directory->child($tgz->basename); | |||||||||
| 128 | 1 | my $destR = $self->pretty_path($dest); | |||||||||
| 129 | |||||||||||
| 130 | 1 | require File::Copy; | |||||||||
| 131 | 1 | ▶ | File::Copy::move($tgz, $dest) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | or $self->log_fatal("Failed to move to $destR: $!"); | ||||||||||
| 133 | |||||||||||
| 134 | 1 | $self->log("Moved to $destR"); | |||||||||
| 135 | } # end release | ||||||||||
| 136 | |||||||||||
| 137 | #--------------------------------------------------------------------- | ||||||||||
| 138 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 139 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 140 | 2 | 1; | |||||||||
| 141 | |||||||||||
| 142 | __END__ | ||||||||||