blib/lib/Dist/Zilla/Plugin/CheckDeploymentHandlerFiles.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 65 CC 2 SCAR 10.6
CC
2
Cov
0%
before_release
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.9
1 package Dist::Zilla::Plugin::CheckDeploymentHandlerFiles;
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '0.006';
7  
8 use Moose;
9 use namespace::autoclean;
10 use File::ShareDir 'module_dir';
11 use File::pushd;
12 use Class::Load 'load_class';
13  
14 with 'Dist::Zilla::Role::BeforeRelease';
15  
16 has schema_module => (
17 is => 'ro',
18 isa => 'Str',
19 lazy => 1,
20 default => sub {
21 my $self = shift;
22 my $name = $self->zilla->name;
23 $name =~ s/-/::/g;
24  
25 $name;
26 }
27 );
28  
29 has script_directory => (
30 is => 'ro',
31 isa => 'Str',
32 lazy => 1,
33 default => sub {
34 my $self = shift;
35 my $mod = $self->schema_module;
36  
37 return module_dir($mod) . '/sql';
38 }
39 );
40  
41 around schema_module => sub {
42 my $orig = shift;
43 my $self = shift;
44 my $mod = $self->$orig(@_);
45  
46 load_class($mod);
47  
48 $mod;
49 };
50  
51 sub before_release {
52 my $self = shift;
53 my $version = $self->schema_module->schema_version || $self->schema_module->version;
54 my $previous = $version - 1;
55  
56 # Make sure we're working in context of the build dir.
57 $self->zilla->ensure_built;
58 my $chdir = pushd($self->zilla->built_in);
59 unshift @INC, $chdir . '/lib';
60  
61 my $script_dir = $self->script_directory . "/PostgreSQL/upgrade/$previous-$version";
62  
63 $self->log( "Checking for $script_dir" );
64  
65 if (! -e $script_dir) {
66 $self->log_fatal("Did not find $script_dir - did you prepare the schema upgrade?");
67 }
68  
69 return;
70 }
71  
72 1;
73  
74 =head1 NAME
75  
76 Dist::Zilla::Plugin::CheckDeploymentHandlerFiles - Check you've created the DH files for this version
77  
78 =head1 SYNOPSIS
79  
80 [CheckDeploymentHandlerFiles]
81  
82 =head1 DESCRIPTION
83  
84 If you have a schema that uses L<DBIx::Class::DeploymentHandler> then your
85 deployment will bail if you don't have a directory for migrating to the current
86 version. If your schema is part of a wider module it's fairly likely that you'll
87 forget to create these files because you didn't do any work on the schema.
88  
89 This plugin simply bails if there's no C<x-y> directory where DH would normally
90 put them.
91  
92 =head1 TODO
93  
94 Configuration so that the user can replicate any customisation of
95 DeploymentHandler, thus searching for the correct directory.
96  
97 =head1 BUGS
98  
99 Report any issues on the github bugtracker.
100  
101 =head1 AUTHOR
102  
103 Alastair McGowan-Douglas <altreus@altre.us>
104  
105 =head1 COPYRIGHT AND LICENSE
106  
107 This software is Copyright (c) 2016 by Alastair McGowan-Douglas.
108  
109 This is free software, licensed under:
110  
111 The (three-clause) BSD License
112  
113 =head1 SEE ALSO
114  
115 =over
116  
117 =item L<DBIx::Class>
118  
119 =item L<DBIx::Class::DeploymentHandler>
120  
121 =back
122