| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::TemplateCMD::Command; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Created on: 2008-09-04 04:26:46 | 
| 4 |  |  |  |  |  |  | # Create by:  ivan | 
| 5 |  |  |  |  |  |  | # $Id$ | 
| 6 |  |  |  |  |  |  | # $Revision$, $HeadURL$, $Date$ | 
| 7 |  |  |  |  |  |  | # $Revision$, $Source$, $Date$ | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 9 |  |  | 9 |  | 2035 | use strict; | 
|  | 9 |  |  |  |  | 45 |  | 
|  | 9 |  |  |  |  | 293 |  | 
| 10 | 9 |  |  | 9 |  | 53 | use warnings; | 
|  | 9 |  |  |  |  | 23 |  | 
|  | 9 |  |  |  |  | 242 |  | 
| 11 | 9 |  |  | 9 |  | 485 | use version; | 
|  | 9 |  |  |  |  | 1935 |  | 
|  | 9 |  |  |  |  | 84 |  | 
| 12 | 9 |  |  | 9 |  | 673 | use Carp; | 
|  | 9 |  |  |  |  | 61 |  | 
|  | 9 |  |  |  |  | 594 |  | 
| 13 | 9 |  |  | 9 |  | 706 | use Data::Dumper qw/Dumper/; | 
|  | 9 |  |  |  |  | 7211 |  | 
|  | 9 |  |  |  |  | 503 |  | 
| 14 | 9 |  |  | 9 |  | 618 | use English qw/ -no_match_vars /; | 
|  | 9 |  |  |  |  | 1874 |  | 
|  | 9 |  |  |  |  | 108 |  | 
| 15 | 9 |  |  | 9 |  | 3274 | use base qw/Exporter/; | 
|  | 9 |  |  |  |  | 20 |  | 
|  | 9 |  |  |  |  | 5189 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | our $VERSION     = version->new('0.6.10'); | 
| 18 |  |  |  |  |  |  | our @EXPORT_OK   = qw//; | 
| 19 |  |  |  |  |  |  | our %EXPORT_TAGS = (); | 
| 20 |  |  |  |  |  |  | #our @EXPORT      = qw//; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub args { | 
| 23 |  |  |  |  |  |  | return ( | 
| 24 | 0 |  |  | 0 | 1 |  | 'path|p=s', | 
| 25 |  |  |  |  |  |  | ); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  | 0 | 1 |  | sub default { | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub get_template { | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  | 0 | 1 |  | my ($self, $template, $cmd) = @_; | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # try to get the template directly by name | 
| 36 | 0 |  |  |  |  |  | for my $provider (@{ $cmd->{providers} }) { | 
|  | 0 |  |  |  |  |  |  | 
| 37 | 0 | 0 |  |  |  |  | if ($provider->{INCLUDE_PATH}) { | 
| 38 | 0 |  |  |  |  |  | for my $path (@{ $provider->{INCLUDE_PATH} }) { | 
|  | 0 |  |  |  |  |  |  | 
| 39 | 0 |  |  |  |  |  | my ($data, $error) = $provider->_load( "$path/$template" ); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 | 0 |  |  |  |  | if ($data->{text}) { | 
| 42 |  |  |  |  |  |  | # return the found template info | 
| 43 | 0 |  |  |  |  |  | return ($data, $provider, $error, [$template]); | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  | else { | 
| 48 | 0 |  |  |  |  |  | my ($data, $error) = $provider->_load( $template ); | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 0 | 0 |  |  |  |  | if ($data->{text}) { | 
| 51 |  |  |  |  |  |  | # return the found template info | 
| 52 | 0 |  |  |  |  |  | return ($data, $provider, $error, [$template]); | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 0 | 0 |  |  |  |  | if ($cmd->{verbose}) { | 
| 57 | 0 |  |  |  |  |  | print "$template was not found with provider " . ( ref $provider ) . "\n"; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | # now try to get the template assumin it is missing its suffix | 
| 62 | 0 |  |  |  |  |  | my @files = map {$_->{file}} $cmd->list_templates(); | 
|  | 0 |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # get all templates that start with the template name provided | 
| 65 | 0 |  |  |  |  |  | my @templates = grep { m{^$template [.] .+ $}xms } @files; | 
|  | 0 |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 | 0 |  |  |  |  | if (@templates) { | 
| 68 | 0 |  |  |  |  |  | for my $provider (@{ $cmd->{providers} }) { | 
|  | 0 |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  |  | my ($data, $error) = $provider->_load( $templates[0] ); | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 0 | 0 |  |  |  |  | if ($data->{text}) { | 
| 72 |  |  |  |  |  |  | # return the found template info | 
| 73 | 0 |  |  |  |  |  | return ($data, $provider, $error, \@templates); | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | # no template found | 
| 79 | 0 |  |  |  |  |  | croak "The template $template was not found!"; | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | 1; | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | __END__ |