File Coverage

blib/lib/Pinto/Action/New.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Create a new empty stack
2              
3             package Pinto::Action::New;
4              
5 51     51   34649 use Moose;
  51         148  
  51         525  
6 51     51   430502 use MooseX::StrictConstructor;
  51         167  
  51         570  
7 51     51   205252 use MooseX::Types::Moose qw(Bool Str);
  51         151  
  51         884  
8 51     51   265763 use MooseX::MarkAsMethods ( autoclean => 1 );
  51         168  
  51         562  
9              
10 51     51   220130 use Pinto::Types qw(StackName PerlVersion);
  51         130  
  51         654  
11              
12             #------------------------------------------------------------------------------
13              
14             our $VERSION = '0.14'; # VERSION
15              
16             #------------------------------------------------------------------------------
17              
18             extends qw( Pinto::Action );
19              
20             #------------------------------------------------------------------------------
21              
22             with qw( Pinto::Role::Transactional );
23              
24             #------------------------------------------------------------------------------
25              
26             has stack => (
27             is => 'ro',
28             isa => StackName,
29             required => 1,
30             );
31              
32             has default => (
33             is => 'ro',
34             isa => Bool,
35             default => 0,
36             );
37              
38             has description => (
39             is => 'ro',
40             isa => Str,
41             predicate => 'has_description',
42             );
43              
44             has target_perl_version => (
45             is => 'ro',
46             isa => PerlVersion,
47             predicate => 'has_target_perl_version',
48             coerce => 1,
49             );
50              
51             #------------------------------------------------------------------------------
52              
53             sub execute {
54             my ($self) = @_;
55              
56             my %attrs = ( name => $self->stack );
57             my $stack = $self->repo->create_stack(%attrs);
58              
59             $stack->set_properties( $stack->default_properties );
60              
61             $stack->set_property( description => $self->description )
62             if $self->has_description;
63              
64             $stack->set_property( target_perl_version => $self->target_perl_version )
65             if $self->has_target_perl_version;
66              
67             $stack->mark_as_default
68             if $self->default;
69              
70             return $self->result->changed;
71             }
72              
73             #------------------------------------------------------------------------------
74              
75             __PACKAGE__->meta->make_immutable;
76              
77             #------------------------------------------------------------------------------
78              
79             1;
80              
81             __END__
82              
83             =pod
84              
85             =encoding UTF-8
86              
87             =for :stopwords Jeffrey Ryan Thalhammer
88              
89             =head1 NAME
90              
91             Pinto::Action::New - Create a new empty stack
92              
93             =head1 VERSION
94              
95             version 0.14
96              
97             =head1 AUTHOR
98              
99             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut