File Coverage

blib/lib/App/Scaffolder/Puppet/Command.pm
Criterion Covered Total %
statement 38 39 97.4
branch 2 4 50.0
condition 5 9 55.5
subroutine 12 12 100.0
pod 6 6 100.0
total 63 70 90.0


line stmt bran cond sub pod time code
1             package App::Scaffolder::Puppet::Command;
2             $App::Scaffolder::Puppet::Command::VERSION = '0.003000';
3 3     3   45571 use parent qw(App::Scaffolder::Command);
  3         7  
  3         18  
4              
5             # ABSTRACT: Base class for App::Scaffolder::Puppet commands
6              
7 3     3   105526 use strict;
  3         6  
  3         52  
8 3     3   13 use warnings;
  3         5  
  3         77  
9              
10 3     3   15 use File::Spec::Functions qw(catdir);
  3         7  
  3         135  
11 3     3   17 use MRO::Compat;
  3         6  
  3         48  
12 3     3   13 use Path::Class::Dir;
  3         6  
  3         949  
13              
14              
15             sub get_target {
16 5     5 1 5163 my ($self, $opt) = @_;
17 5   66     33 my $target = $opt->target() || (
18             $opt->name() =~ m{::}x
19             ? '.'
20             : $opt->name()
21             );
22 5         396 return Path::Class::Dir->new($target);
23             }
24              
25              
26              
27             sub get_variables {
28 5     5 1 3351 my ($self, $opt) = @_;
29              
30 5         30 my @name_parts = split(/::/x, $opt->name());
31 5         245 my (undef, @subname_parts) = @name_parts;
32 5   66     26 my $package = $opt->package() || $opt->name();
33             return {
34 5         380 name => scalar $opt->name(),
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 197 return 'App-Scaffolder-Puppet';
49             }
50              
51              
52              
53             sub get_options {
54 2     2 1 62300 my ($class) = @_;
55             return (
56 2         24 [ '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 4816 my ($self, $opt, $args) = @_;
65              
66 2         21 $self->next::method($opt, $args);
67 2 50 33     133 unless ($self->contains_base_args($opt) || $opt->name()) {
68 0         0 $self->usage_error("Parameter 'name' required");
69             }
70 2         40 return;
71             }
72              
73              
74              
75             sub get_extra_template_dirs {
76 3     3 1 2688 my ($self, $command) = @_;
77              
78 3         14 my @sub_path = ('etc', 'puppet', 'scaffolder_templates', $command);
79 3 50       55 my @extra_template_dirs = grep { -d $_ && -r $_ } (
  6         492  
80             Path::Class::Dir->new('', @sub_path),
81             Path::Class::Dir->new('', 'usr', 'local', @sub_path),
82             );
83              
84             return (
85 3         178 $self->next::method($command),
86             @extra_template_dirs,
87             );
88             }
89              
90              
91             1;
92              
93             __END__