Lemplate
view release on metacpan or search on metacpan
sub main {
my $class = shift;
my @argv = @_;
my ($template_options, $lemplate_options) = get_options(@argv);
my ($runtime, $compile, $list) = @$lemplate_options{qw/runtime compile list/};
if ($runtime) {
print runtime_source_code(@$lemplate_options{qw/runtime ajax json xhr xxx compact/});
return unless $compile;
}
my $templates = make_file_list($lemplate_options->{exclude}, @argv);
print_usage_and_exit() unless @$templates;
if ($list) {
foreach (@$templates) {
print STDOUT $_->{short} . "\n";
}
return;
}
if ($compile) {
my $lemplate = Lemplate->new(%$template_options);
print STDOUT $lemplate->_preamble;
for (my $i = 0; $i < @$templates; $i++) {
my $template = $templates->[$i];
#warn "processing $template->{short}";
my $content = slurp($template->{full});
if ($content) {
%ExtraTemplates = ();
print STDOUT $lemplate->compile_template_content(
$content,
$template->{short}
);
my @new_files;
for my $new_template (keys %ExtraTemplates) {
if (!$ProcessedTemplates{$new_template}) {
if (!-f $new_template) {
$new_template = "t/data/" . $new_template;
}
#warn $new_template;
if (-f $new_template) {
#warn "adding new template $new_template";
push @new_files, $new_template;
}
}
}
push @$templates, @{ make_file_list({}, @new_files) };
}
}
print STDOUT "return _M\n";
return;
}
print_usage_and_exit();
}
sub get_options {
local @ARGV = @_;
my $runtime;
my $compile = 0;
my $list = 0;
my $start_tag = exists $ENV{LEMPLATE_START_TAG}
? $ENV{LEMPLATE_START_TAG}
: undef;
my $end_tag = exists $ENV{LEMPLATE_END_TAG}
? $ENV{LEMPLATE_END_TAG}
: undef;
my $pre_chomp = exists $ENV{LEMPLATE_PRE_CHOMP}
? $ENV{LEMPLATE_PRE_CHOMP}
: undef;
my $post_chomp = exists $ENV{LEMPLATE_POST_CHOMP}
? $ENV{LEMPLATE_POST_CHOMP}
: undef;
my $trim = exists $ENV{LEMPLATE_TRIM}
? $ENV{LEMPLATE_TRIM}
: undef;
my $anycase = exists $ENV{LEMPLATE_ANYCASE}
? $ENV{LEMPLATE_ANYCASE}
: undef;
my $eval_javascript = exists $ENV{LEMPLATE_EVAL_JAVASCRIPT}
? $ENV{LEMPLATE_EVAL_JAVASCRIPT}
: 1;
my $source = 0;
my $exclude = 0;
my ($ajax, $json, $xxx, $xhr, $compact, $minify);
my $help = 0;
my @include_paths;
GetOptions(
"compile|c" => \$compile,
"list|l" => \$list,
"runtime|r:s" => \$runtime,
"start-tag=s" => \$start_tag,
"end-tag=s" => \$end_tag,
"trim=s" => \$trim,
"pre-chomp" => \$pre_chomp,
"post-chomp" => \$post_chomp,
"any-case" => \$anycase,
"eval!" => \$eval_javascript,
"source|s" => \$source,
"exclude=s" => \$exclude,
"ajax:s" => \$ajax,
"json:s" => \$json,
"xxx" => \$xxx,
"xhr:s" => \$xhr,
"include_path" => \@include_paths,
"compact" => \$compact,
"minify:s" => \$minify,
"help|?" => \$help,
( run in 0.755 second using v1.01-cache-2.11-cpan-364913b4093 )