From d4544be59e056350dd147225045b9a05bf845f75 Mon Sep 17 00:00:00 2001 From: "Stefan Hornburg (Racke)" Date: Fri, 11 Mar 2011 18:09:32 +0100 Subject: [PATCH] Derive location of specification file from template file if not present at bootstrap time. --- lib/Template/Zoom.pm | 12 +++++++++++- lib/Template/Zoom/Utils.pm | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lib/Template/Zoom/Utils.pm diff --git a/lib/Template/Zoom.pm b/lib/Template/Zoom.pm index 76dee52..460d764 100644 --- a/lib/Template/Zoom.pm +++ b/lib/Template/Zoom.pm @@ -22,6 +22,7 @@ package Template::Zoom; use strict; use warnings; +use Template::Zoom::Utils; use Template::Zoom::Specification::XML; use Template::Zoom::HTML; @@ -41,6 +42,15 @@ sub _bootstrap { my ($parser_name, $parser_spec, $spec_file, $spec, $template_file, $template_object); unless ($self->{specification}) { + unless ($self->{specification_file}) { + # try to derive specification file name from template file name + $self->{specification_file} = Template::Zoom::Utils::derive_filename($self->{template_file}, '.xml'); + + unless (-f $self->{specification_file}) { + die "Missing Template::Zoom specification for template $self->{template_file}\n"; + } + } + if ($parser_name = $self->{specification_parser}) { # load parser class my $class; @@ -75,7 +85,7 @@ sub _bootstrap { } } else { - die "$0: Missing Template::Zoom specification.\n"; + die "$0: Missing Template::Zoom specification, template: $self->{template_file}.\n"; } } diff --git a/lib/Template/Zoom/Utils.pm b/lib/Template/Zoom/Utils.pm new file mode 100644 index 0000000..2f9b63b --- /dev/null +++ b/lib/Template/Zoom/Utils.pm @@ -0,0 +1,37 @@ +# Template::Zoom::Utils - Template::Zoom utility functions +# +# Copyright (C) 2010-2011 Stefan Hornburg (Racke) . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +package Template::Zoom::Utils; + +use strict; +use warnings; + +use File::Basename; +use File::Spec; + +sub derive_filename { + my ($orig_filename, $suffix) = @_; + my ($orig_dir, @frags); + + @frags = fileparse($orig_filename, qr/\.[^.]*/); + + return $frags[1] . $frags[0] . $suffix; +} + +1;