File Coverage

blib/lib/DBIx/Class/DeploymentHandler/WithReasonableDefaults.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package DBIx::Class::DeploymentHandler::WithReasonableDefaults;
2             $DBIx::Class::DeploymentHandler::WithReasonableDefaults::VERSION = '0.002233';
3 12     12   7512 use Moose::Role;
  12         32  
  12         129  
4              
5             # ABSTRACT: Make default arguments to a few methods sensible
6              
7             requires qw( prepare_upgrade prepare_downgrade initial_version schema_version );
8              
9             around prepare_upgrade => sub {
10             my $orig = shift;
11             my $self = shift;
12             my $args = shift || {};
13              
14             $args->{from_version} ||= $self->initial_version;
15             $args->{to_version} ||= $self->schema_version;
16             $args->{version_set} ||= [$args->{from_version}, $args->{to_version}];
17              
18             $self->$orig($args);
19             };
20              
21              
22             around prepare_downgrade => sub {
23             my $orig = shift;
24             my $self = shift;
25              
26             my $args = shift || {};
27              
28             $args->{to_version} ||= $self->initial_version;
29             $args->{from_version} ||= $self->schema_version;
30             $args->{version_set} ||= [$args->{from_version}, $args->{to_version}];
31              
32             $self->$orig($args);
33             };
34              
35             around install_resultsource => sub {
36             my $orig = shift;
37             my $self = shift;
38             my $source = shift;
39             my $version = shift || $self->to_version;
40              
41             $self->$orig($source, $version);
42             };
43              
44             1;
45              
46             =pod
47              
48             =head1 NAME
49              
50             DBIx::Class::DeploymentHandler::WithReasonableDefaults - Make default arguments to a few methods sensible
51              
52             =head1 CONVENIENCE
53              
54             The whole point of this role is to set defaults for arguments of various
55             methods. It's a little awesome.
56              
57             =head1 METHODS
58              
59             =head2 prepare_upgrade
60              
61             Defaulted args:
62              
63             my $from_version = $self->initial_version;
64             my $to_version = $self->schema_version;
65             my $version_set = [$from_version, $to_version];
66              
67             =head2 prepare_downgrade
68              
69             Defaulted args:
70              
71             my $from_version = $self->schema_version;
72             my $to_version = $self->data_version;
73             my $version_set = [$from_version, $to_version];
74              
75             =head2 install_resultsource
76              
77             Defaulted args:
78              
79             my $version = $self->to_version;
80              
81             =head1 AUTHOR
82              
83             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
84              
85             =head1 COPYRIGHT AND LICENSE
86              
87             This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
88              
89             This is free software; you can redistribute it and/or modify it under
90             the same terms as the Perl 5 programming language system itself.
91              
92             =cut
93              
94             __END__
95              
96             vim: ts=2 sw=2 expandtab
97