| 1 | package Helm::Task; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use Moose; | ||
| 5 | use namespace::autoclean; | ||
| 6 | use Data::UUID; | ||
| 7 | use File::Spec::Functions qw(catfile); | ||
| 8 | |||
| 9 | has helm => (is => 'ro', writer => '_helm', isa => 'Helm'); | ||
| 10 | |||
| 11 | # must be implemented in child classes | ||
| 12 | sub execute { | ||
| 13 | my ($self, %args) = @_; | ||
| 14 | die "You must implement the execute method in your child class " . ref($self) . "!"; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub validate { | ||
| 18 | my $self = shift; | ||
| 19 | die "You must implement the validate method in your child class " . ref($self) . "!"; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub help { | ||
| 23 | my ($self, $task) = @_; | ||
| 24 | return qq(No help documentation for "$task". Bug your implementers); | ||
| 25 | } | ||
| 26 | |||
| 27 | # can be implemented in child classes | ||
| 28 | sub setup { } | ||
| 29 | sub teardown { } | ||
| 30 | |||
| 31 | sub unique_tmp_file { | ||
| 32 | my ($self, %args) = @_; | ||
| 33 | my $file = catfile('', 'tmp', Data::UUID->new->create_str); | ||
| 34 | $file = $args{prefix} . $file if $args{prefix}; | ||
| 35 | $file .= $args{suffix} if $args{suffix}; | ||
| 36 | return $file; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub param { | ||
| 40 | my $self = shift; | ||
| 41 | my $name = shift; | ||
| 42 | die "param() requires a name" unless $name; | ||
| 43 | $self->{__params} ||= {}; | ||
| 44 | my $params = $self->{__params}; | ||
| 45 | |||
| 46 | # set it if we have a value | ||
| 47 | $params->{$name} = $_[0] if @_; | ||
| 48 | return $params->{$name}; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub params { | ||
| 52 | my $self = shift; | ||
| 53 | if( $self->{__params} ) { | ||
| 54 | return %{$self->{__params}}; | ||
| 55 | } else { | ||
| 56 | return (); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | __PACKAGE__->meta->make_immutable; | ||
| 61 | |||
| 62 | 1; |