Skip to content
Browse files

Changed to using share_dir to distribute templates

  • Loading branch information...
1 parent 9b9605b commit f9736a57953506a4cb9b7832c8b6c43865931cc4 @ivanwills committed May 13, 2012
Showing with 40 additions and 43 deletions.
  1. +1 −1 .gitignore
  2. +5 −0 Build.PL
  3. +34 −35 lib/App/TemplateCMD.pm
  4. +0 −1 lib/App/TemplateCMD/Command/Print.pm
  5. +0 −6 lib/App/TemplateCMD/Templates.pm
View
2 .gitignore
@@ -18,5 +18,5 @@ nytprof*
tmp*
*~
vim.sh
-temp*
+temp/*
errors.err
View
5 Build.PL
@@ -24,6 +24,11 @@ my $builder = Module::Build->new(
'Test::More' => 0,
'Test::NoWarnings' => 0,
},
+ share_dir => {
+ dist => [
+ 'templates',
+ ],
+ },
add_to_cleanup => [ 'App-TemplateCMD-*' ],
create_makefile_pl => 'traditional',
create_license => 1,
View
69 lib/App/TemplateCMD.pm
@@ -18,8 +18,8 @@ use YAML qw/Dump LoadFile/;
use Readonly;
use Template;
use Template::Provider;
-use Template::Provider::FromDATA;
use Data::Merger qw/merger/;
+use File::ShareDir qw/dist_dir/;
use base qw/Exporter/;
our $VERSION = version->new('0.1.1');
@@ -121,7 +121,6 @@ sub process {
$self->{providers} = [
Template::Provider->new({ INCLUDE_PATH => $path }),
- Template::Provider::FromDATA->new({ CLASSES => $self->{template_modules} }),
];
$self->{template} = Template->new({
@@ -185,7 +184,7 @@ sub config {
return $self->{'config'} if $self->{'config'};
my $conf = {
- path => '~/template-cmd:~/.template-cmd/:~/.template-cmd-local:/usr/local/template-cmd/src/',
+ path => '~/template-cmd:~/.template-cmd/:~/.template-cmd-local:/usr/local/template-cmd/src/:' . dist_dir('App-TemplateCMD'),
aliases => {
ls => 'list',
des => 'describe',
@@ -326,38 +325,38 @@ sub list_templates {
);
}
- $self->{providers}[0]->_load('__');
- if ( $self->{providers}[0]->can('cache') ) {
- push @files, map {{ file => $_ }} keys %{ $self->{providers}[0]->cache->{templates} };
- }
-
- for my $module (@{ $self->{template_modules} }) {
- my $file = $module;
- $file =~ s{::}{/}gxms;
- $file .= '.pm';
- require $file;
-
- my $fh;
- {
- no strict 'refs'; ## no critic
- $fh = \*{"${module}\::DATA"};
- }
- my $lines = 0;
-
- LINE:
- while ( my $line = <$fh> ) {
- $lines++;
- my ($template) = $line =~ /^__(.+)__\r?\n/xms;
- next LINE if !$template;
- push @files, { path => $module, file => $template };
- }
-
- # if no lines read check the provider cache
- if ( !$lines ) {
- my $cache = $self->{providers}[1]->{cache}{templates};
- push @files, map {{ file => $_ }} keys %{ $cache };
- }
- }
+ #$self->{providers}[0]->_load('__');
+ #if ( $self->{providers}[0]->can('cache') ) {
+ # push @files, map {{ file => $_ }} keys %{ $self->{providers}[0]->cache->{templates} };
+ #}
+
+ #for my $module (@{ $self->{template_modules} }) {
+ # my $file = $module;
+ # $file =~ s{::}{/}gxms;
+ # $file .= '.pm';
+ # require $file;
+
+ # my $fh;
+ # {
+ # no strict 'refs'; ## no critic
+ # $fh = \*{"${module}\::DATA"};
+ # }
+ # my $lines = 0;
+
+ # LINE:
+ # while ( my $line = <$fh> ) {
+ # $lines++;
+ # my ($template) = $line =~ /^__(.+)__\r?\n/xms;
+ # next LINE if !$template;
+ # push @files, { path => $module, file => $template };
+ # }
+
+ # # if no lines read check the provider cache
+ # if ( !$lines ) {
+ # my $cache = $self->{providers}[1]->{cache}{templates};
+ # push @files, map {{ file => $_ }} keys %{ $cache };
+ # }
+ #}
return @files;
}
View
1 lib/App/TemplateCMD/Command/Print.pm
@@ -15,7 +15,6 @@ use Data::Dumper qw/Dumper/;
use English qw/ -no_match_vars /;
use Template;
use Template::Provider;
-use Template::Provider::FromDATA;
use IPC::Open2;
use base qw/App::TemplateCMD::Command/;
View
6 lib/App/TemplateCMD/Templates.pm
@@ -31,14 +31,8 @@ This documentation refers to App::TemplateCMD::Templates version 0.1.0.
=head1 SYNOPSIS
use Template;
- use Template::Provider::FromDATA;
use App::TemplateCMD::Templates;
- # Get the template provider
- my $provider = Template::Provider::FromDATA->new({
- CLASSES => 'App::TemplateCMD::Templates',
- });
-
# Create the new template object
my $template = Template->new({
LOAD_TEMPLATES => [$provider],

0 comments on commit f9736a5

Please sign in to comment.
Something went wrong with that request. Please try again.