akefile.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 75 CC 2 SCAR 10.6
CC
2
Cov
0%
import
6.0
get_data
2.0
BEGIN
2.0
CRAP 2.9
1 use File::Share();
2 use IO::All();
3 use Mo();
4 use Template::Toolkit::Simple();
5  
6 package akefile;
7 use Mo qw'default builder';
8 our $VERSION = '0.08';
9  
10 use IO::All;
11  
12 has type => ();
13 has args => (default => sub{[]});
14 has data => (builder => 'get_data');
15 has target_file => (default => sub {'Makefile.PL'});
16 has run_command => (default => sub {"$^X Makefile.PL"});
17  
18 sub import {
19 my $pkg = shift;
20 my $type = shift or return;
21 my $self = $pkg->new(
22 type => $type,
23 );
24 $self->args([@_]);
25  
26 my ($main, $e) = caller(0);
27 return unless $main eq 'main' and $e eq '-e' or $e eq '-';
28  
29 my $path = File::Share::dist_file(__PACKAGE__, $type)
30 or die "'$type' is not a currently know akefile type";
31 my $template = io($path)->all;
32  
33 Template::Toolkit::Simple->new()
34 ->path([File::Share::dist_dir(__PACKAGE__)])
35 ->data($self->data)
36 ->output($self->target_file)
37 ->render(\$template);
38  
39 exec $self->run_command;
40 }
41  
42 sub get_data {
43 my $self = shift;
44 my $data = {
45 map {
46 split '=', $_, 2;
47 } grep {
48 $_ =~ /=/;
49 } @{$self->args}
50 };
51 return $data;
52 }
53  
54 1;