File Coverage

blib/lib/App/Scaffolder/Puppet/Command.pm
Criterion Covered Total %
statement 38 39 97.4
branch 2 4 50.0
condition 8 13 61.5
subroutine 12 12 100.0
pod 6 6 100.0
total 66 74 89.1


line stmt bran cond sub pod time code
1             package App::Scaffolder::Puppet::Command;
2             $App::Scaffolder::Puppet::Command::VERSION = '0.003001';
3 3     3   43439 use parent qw(App::Scaffolder::Command);
  3         9  
  3         17  
4              
5             # ABSTRACT: Base class for App::Scaffolder::Puppet commands
6              
7 3     3   75207 use strict;
  3         7  
  3         47  
8 3     3   12 use warnings;
  3         7  
  3         71  
9              
10 3     3   19 use File::Spec::Functions qw(catdir);
  3         7  
  3         121  
11 3     3   15 use MRO::Compat;
  3         5  
  3         49  
12 3     3   12 use Path::Class::Dir;
  3         6  
  3         1010  
13              
14              
15             sub get_target {
16 5     5 1 5080 my ($self, $opt) = @_;
17 5   66     29 my $target = $opt->target() || (
18             $opt->name() =~ m{::}x
19             ? '.'
20             : $opt->name()
21             );
22 5         387 return Path::Class::Dir->new($target);
23             }
24              
25              
26              
27             sub get_variables {
28 5     5 1 1174 my ($self, $opt) = @_;
29              
30 5         27 my @name_parts = split(/::/x, $opt->name());
31 5         200 my (undef, @subname_parts) = @name_parts;
32 5   66     24 my $package = $opt->package() || $opt->name();
33             return {
34 5   50     287 name => scalar $opt->name(),
      100        
35             nameparts => \@name_parts,
36             namepartsjoined => join('_', @name_parts),
37             namepartspath => catdir(@name_parts) || '',
38             subnameparts => \@subname_parts,
39             subnamepartsjoined => join('_', @subname_parts),
40             subnamepartspath => catdir(@subname_parts) || '',
41             package => $package,
42             };
43             }
44              
45              
46              
47             sub get_dist_name {
48 4     4 1 216 return 'App-Scaffolder-Puppet';
49             }
50              
51              
52              
53             sub get_options {
54 2     2 1 49488 my ($class) = @_;
55             return (
56 2         31 [ 'name|n=s' => 'Name of the new Puppet module/class that should be created' ],
57             [ 'package|p=s' => 'Name of a package that should be available in templates '
58             . '(defaults to the value of the --name parameter)' ],
59             );
60             }
61              
62              
63             sub validate_args {
64 2     2 1 5343 my ($self, $opt, $args) = @_;
65              
66 2         20 $self->next::method($opt, $args);
67 2 50 33     158 unless ($self->contains_base_args($opt) || $opt->name()) {
68 0         0 $self->usage_error("Parameter 'name' required");
69             }
70 2         41 return;
71             }
72              
73              
74              
75             sub get_extra_template_dirs {
76 3     3 1 4263 my ($self, $command) = @_;
77              
78 3         16 my @sub_path = ('etc', 'puppet', 'scaffolder_templates', $command);
79 3 50       57 my @extra_template_dirs = grep { -d $_ && -r $_ } (
  6         558  
80             Path::Class::Dir->new('', @sub_path),
81             Path::Class::Dir->new('', 'usr', 'local', @sub_path),
82             );
83              
84             return (
85 3         189 $self->next::method($command),
86             @extra_template_dirs,
87             );
88             }
89              
90              
91             1;
92              
93             __END__