| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::TemplateCMD::Command::Build; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Created on: 2008-03-26 13:43:32 | 
| 4 |  |  |  |  |  |  | # Create by:  ivanw | 
| 5 |  |  |  |  |  |  | # $Id$ | 
| 6 |  |  |  |  |  |  | # $Revision$, $HeadURL$, $Date$ | 
| 7 |  |  |  |  |  |  | # $Revision$, $Source$, $Date$ | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 1819 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 51 |  | 
| 10 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 44 |  | 
| 11 | 2 |  |  | 2 |  | 381 | use version; | 
|  | 2 |  |  |  |  | 1515 |  | 
|  | 2 |  |  |  |  | 10 |  | 
| 12 | 2 |  |  | 2 |  | 115 | use Carp; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 102 |  | 
| 13 | 2 |  |  | 2 |  | 539 | use List::MoreUtils qw/uniq/; | 
|  | 2 |  |  |  |  | 11046 |  | 
|  | 2 |  |  |  |  | 15 |  | 
| 14 | 2 |  |  | 2 |  | 2190 | use Data::Dumper qw/Dumper/; | 
|  | 2 |  |  |  |  | 5701 |  | 
|  | 2 |  |  |  |  | 107 |  | 
| 15 | 2 |  |  | 2 |  | 412 | use English qw/ -no_match_vars /; | 
|  | 2 |  |  |  |  | 1413 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 16 | 2 |  |  | 2 |  | 1076 | use Template; | 
|  | 2 |  |  |  |  | 16125 |  | 
|  | 2 |  |  |  |  | 51 |  | 
| 17 | 2 |  |  | 2 |  | 13 | use Template::Provider; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 50 |  | 
| 18 | 2 |  |  | 2 |  | 413 | use YAML qw/Load/; | 
|  | 2 |  |  |  |  | 5892 |  | 
|  | 2 |  |  |  |  | 84 |  | 
| 19 | 2 |  |  | 2 |  | 1564 | use Path::Tiny; | 
|  | 2 |  |  |  |  | 19182 |  | 
|  | 2 |  |  |  |  | 120 |  | 
| 20 | 2 |  |  | 2 |  | 17 | use base qw/App::TemplateCMD::Command/; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 868 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | our $VERSION     = version->new('0.6.11'); | 
| 23 |  |  |  |  |  |  | our @EXPORT_OK   = qw//; | 
| 24 |  |  |  |  |  |  | our %EXPORT_TAGS = (); | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub process { | 
| 27 | 0 |  |  | 0 | 1 |  | my ($self, $cmd, %option) = @_; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 0 |  |  |  |  |  | my $template = 'build/' . shift @{$option{files}}; | 
|  | 0 |  |  |  |  |  |  | 
| 30 | 0 | 0 |  |  |  |  | my $args     = { %{ $cmd->config }, %{ $option{args} || {} } }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 0 |  |  |  |  |  | my $print = $cmd->load_cmd('print'); | 
| 33 | 0 |  |  |  |  |  | my $out = $print->process( $cmd, %{ $args }, files => [$template] ); | 
|  | 0 |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 0 |  |  |  |  |  | my $structure = Load($out); | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 0 |  |  |  |  |  | for my $file (keys %{ $structure }) { | 
|  | 0 |  |  |  |  |  |  | 
| 38 | 0 |  |  |  |  |  | my $template = $structure->{$file}{template}; | 
| 39 | 0 |  |  |  |  |  | my $file = path($file); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 | 0 | 0 |  |  |  | if ( !-e $file || $option{force} ) { | 
| 42 | 0 |  |  |  |  |  | $file->parent->mkpath(); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | # process the template | 
| 46 |  |  |  |  |  |  | my $out = $print->process( | 
| 47 |  |  |  |  |  |  | $cmd, | 
| 48 |  |  |  |  |  |  | file => $file, | 
| 49 | 0 |  |  |  |  |  | %{ $args }, | 
| 50 | 0 |  |  |  |  |  | %{ $structure->{$file} }, | 
|  | 0 |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | files => [$template] | 
| 52 |  |  |  |  |  |  | ); | 
| 53 | 0 |  |  |  |  |  | my $fh = $file->openw; | 
| 54 | 0 |  |  |  |  |  | print {$fh} $out; | 
|  | 0 |  |  |  |  |  |  | 
| 55 | 0 |  |  |  |  |  | close $fh; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 0 |  |  |  |  |  | return $out; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | sub args { | 
| 62 |  |  |  |  |  |  | return ( | 
| 63 | 0 |  |  | 0 | 1 |  | 'force|f!', | 
| 64 |  |  |  |  |  |  | ); | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub help { | 
| 68 | 0 |  |  | 0 | 1 |  | my ($self) = @_; | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 0 |  |  |  |  |  | return <<"HELP"; | 
| 71 |  |  |  |  |  |  | $0 build [options] build_template | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | Options | 
| 74 |  |  |  |  |  |  | -a --args=str   Arguments to the build template | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | This builds a directory structure baised on the results of a build template | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | HELP | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | 1; | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | __END__ |