File Coverage

blib/lib/Module/Setup/Plugin.pm
Criterion Covered Total %
statement 34 34 100.0
branch 8 8 100.0
condition n/a
subroutine 9 9 100.0
pod 1 4 25.0
total 52 55 94.5


line stmt bran cond sub pod time code
1             package Module::Setup::Plugin;
2 26     26   7406 use strict;
  26         67  
  26         1144  
3 26     26   141 use warnings;
  26         162  
  26         816  
4              
5 26     26   154 use Scalar::Util qw(weaken);
  26         51  
  26         2105  
6              
7 26     26   2025 use Module::Setup::Flavor;
  26         64  
  26         867  
8 26     26   160 use Module::Setup::Path::Dir;
  26         59  
  26         10833  
9              
10             sub new {
11 360     360 0 1692 my($class, %args) = @_;
12 360         2081 my $self = bless { %args }, $class;
13 360         2113 weaken $self->{context};
14 360         1791 $self->register;
15 360         21082 $self;
16             }
17              
18 2     2 0 5 sub register {}
19              
20             sub add_trigger {
21 389     389 0 6785 my($self, @args) = @_;
22 389         2462 $self->{context}->add_trigger(@args);
23             }
24              
25             sub append_template_file {
26 10     10 1 89 my($self, $context, $caller) = @_;
27 10 100       57 $caller = caller unless $caller;
28 10         72 my @template = Module::Setup::Flavor::loader($caller);
29              
30 10         40 for my $tmpl (@template) {
31 12 100       84 if (exists $tmpl->{dir}) {
    100          
32 1         5 Module::Setup::Path::Dir->new($context->distribute->dist_path, split('/', $tmpl->{dir}))->mkpath;
33 1         5 next;
34             } elsif (!exists $tmpl->{file}) {
35 1         8 next;
36             }
37 10         61 my $options = {
38             dist_path => $context->distribute->dist_path->file(split('/', $tmpl->{file})),
39             template => $tmpl->{template},
40             vars => $context->distribute->template_vars,
41             content => undef,
42             };
43 10 100       51 $options->{chmod} = $tmpl->{chmod} if $tmpl->{chmod};
44 10         45 $context->distribute->write_template($context, $options);
45             }
46             }
47              
48             1;
49              
50             __END__