r47058 - in /branches/upstream/libtext-micromason-perl/current: META.yml Makefile.PL MicroMason.pm MicroMason/Base.pm MicroMason/Docs/Changes.pod MicroMason/Docs/ReadMe.pod MicroMason/Docs/ToDo.pod MicroMason/TemplateDir.pm t/08-errors.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Thu Nov 12 04:06:39 UTC 2009
Author: jawnsy-guest
Date: Thu Nov 12 04:05:00 2009
New Revision: 47058
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=47058
Log:
[svn-upgrade] Integrating new upstream version, libtext-micromason-perl (2.05)
Modified:
branches/upstream/libtext-micromason-perl/current/META.yml
branches/upstream/libtext-micromason-perl/current/Makefile.PL
branches/upstream/libtext-micromason-perl/current/MicroMason.pm
branches/upstream/libtext-micromason-perl/current/MicroMason/Base.pm
branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/Changes.pod
branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ReadMe.pod
branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ToDo.pod
branches/upstream/libtext-micromason-perl/current/MicroMason/TemplateDir.pm
branches/upstream/libtext-micromason-perl/current/t/08-errors.t
Modified: branches/upstream/libtext-micromason-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/META.yml?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/META.yml (original)
+++ branches/upstream/libtext-micromason-perl/current/META.yml Thu Nov 12 04:05:00 2009
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Text-MicroMason
-version: 2.04
+version: 2.05
abstract: Simple and Extensible Templating
author:
- Alan Ferrency <ferrency at cpan.org>
@@ -12,6 +12,7 @@
ExtUtils::MakeMaker: 0
requires:
Class::MixinFactory: 0.9
+ Cwd: 2.21
File::Spec: 0.9
no_index:
directory:
Modified: branches/upstream/libtext-micromason-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/Makefile.PL?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/Makefile.PL (original)
+++ branches/upstream/libtext-micromason-perl/current/Makefile.PL Thu Nov 12 04:05:00 2009
@@ -1,4 +1,4 @@
-# $Id: Makefile.PL,v 1.5 2007/12/21 20:29:11 alan Exp $
+# $Id: Makefile.PL,v 1.6 2009/11/11 16:23:36 alan Exp $
use ExtUtils::MakeMaker;
@@ -10,6 +10,7 @@
PREREQ_PM => {
'Class::MixinFactory' => 0.9,
'File::Spec' => 0.9,
+ 'Cwd' => 2.21,
},
ABSTRACT_FROM => 'MicroMason.pm',
Modified: branches/upstream/libtext-micromason-perl/current/MicroMason.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/MicroMason.pm?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/MicroMason.pm (original)
+++ branches/upstream/libtext-micromason-perl/current/MicroMason.pm Thu Nov 12 04:05:00 2009
@@ -1,5 +1,5 @@
package Text::MicroMason;
-$VERSION = '2.04';
+$VERSION = '2.05';
# The #line directive requires Perl 5.6 to work correctly the way we use
# it in Base.
Modified: branches/upstream/libtext-micromason-perl/current/MicroMason/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/MicroMason/Base.pm?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/MicroMason/Base.pm (original)
+++ branches/upstream/libtext-micromason-perl/current/MicroMason/Base.pm Thu Nov 12 04:05:00 2009
@@ -63,15 +63,26 @@
# $code_ref = $mason->compile( file => $filename, %options );
# $code_ref = $mason->compile( handle => $filehandle, %options );
sub compile {
- my ( $self, $src_type, $src_data, %options ) = @_;
-
- ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data,%options);
-
- my $code = $self->interpret( $src_type, $src_data );
-
- $self->eval_sub( $code )
- or $self->croak_msg( "MicroMason compilation failed: $@\n$code\n" )
-}
+ my ( $self, $src_type, $src_data, %options ) = @_;
+
+ ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data,%options);
+
+ my $code = $self->interpret( $src_type, $src_data );
+
+ $self->eval_sub( $code )
+ or $self->croak_msg( "MicroMason compilation failed: $@\n". _number_lines($code)."\n" );
+
+}
+
+# Internal helper to number the lines in the compiled template when compilation croaks
+sub _number_lines {
+ my $code = shift;
+
+ my $n = 0;
+ return join("\n", map { sprintf("%4d %s", $n++, $_) } split(/\n/, $code)).
+ "\n** Please use Text::MicroMason->new\(-LineNumbers\) for better diagnostics!";
+}
+
######################################################################
@@ -114,19 +125,20 @@
# $line_number_comment = $mason->source_file_line_label( $src_type, $src_data );
sub source_file_line_label {
- my ( $self, $src_type, $src_data ) = @_;
-
- if ( $src_type eq 'file' ) {
- return '# line 0 "' . $src_data . '"'
- }
-
- my @caller;
- my $call_level ;
- do { @caller = caller( ++ $call_level ) }
- while ( $caller[0] =~ /^Text::MicroMason/ or $self->isa($caller[0]) );
- my $package = ( $caller[1] || $0 );
- qq{# line 0 "text template (compiled at $package line $caller[2])"}
-}
+ my ( $self, $src_type, $src_data ) = @_;
+
+ if ( $src_type eq 'file' ) {
+ return qq(# line 1 "$src_data");
+ }
+
+ my @caller;
+ my $call_level;
+ do { @caller = caller( ++ $call_level ) }
+ while ( $caller[0] =~ /^Text::MicroMason/ or $self->isa($caller[0]) );
+ my $package = ( $caller[1] || $0 );
+ qq{# line 1 "text template (compiled at $package line $caller[2])"}
+}
+
######################################################################
Modified: branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/Changes.pod
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/Changes.pod?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/Changes.pod (original)
+++ branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/Changes.pod Thu Nov 12 04:05:00 2009
@@ -5,6 +5,29 @@
=head1 VERSION 2 HISTORY
+=head2 Version 2.05
+
+=over 4
+
+=item 2009-11-10
+
+Modify compilation error reporting: provide line numbers when dumping
+the compiled template into $@, and change the #line to match the line
+numbering correctly.
+
+=item 2009-11-11
+
+Fix bug reported by CPAN testers on some Windows boxes: use
+Cwd::abs_path for strict_root checking to avoid literal path separators
+in TemplateDir.pm.
+
+=item 2009-11-11
+
+Add a hint about -LineNumbers in the numbered template dump when a
+compilation error occurs.
+
+=back
+
=head2 Version 2.04
=over 4
Modified: branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ReadMe.pod
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ReadMe.pod?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ReadMe.pod (original)
+++ branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ReadMe.pod Thu Nov 12 04:05:00 2009
@@ -50,7 +50,7 @@
=head1 DISTRIBUTION STATUS
-This is version 2.04 of Text::MicroMason.
+This is version 2.05 of Text::MicroMason.
This module has been available on CPAN for over six years.
Modified: branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ToDo.pod
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ToDo.pod?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ToDo.pod (original)
+++ branches/upstream/libtext-micromason-perl/current/MicroMason/Docs/ToDo.pod Thu Nov 12 04:05:00 2009
@@ -39,10 +39,8 @@
=item *
-AutoLoad mixin. Using this mixin adds
-an AUTOLOADER to the mason object, which interprets all unknown
-method calls as template names, which will be interpreted as the
-object is compiled.
+AutoLoad mixin. Using this mixin adds an AUTOLOADER to the mason object,
+which interprets all unknown method calls as template names.
=back
Modified: branches/upstream/libtext-micromason-perl/current/MicroMason/TemplateDir.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/MicroMason/TemplateDir.pm?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/MicroMason/TemplateDir.pm (original)
+++ branches/upstream/libtext-micromason-perl/current/MicroMason/TemplateDir.pm Thu Nov 12 04:05:00 2009
@@ -2,30 +2,30 @@
use strict;
use File::Spec;
+use Cwd;
######################################################################
sub prepare {
- my ( $self, $src_type, $src_data ) = @_;
-
- return $self->NEXT('prepare', $src_type, $src_data )
- unless $src_type eq 'file';
-
- my $path = $self->resolve_path($src_data);
- return $self->NEXT('prepare', 'file' => $path, source_file => $path );
+ my ( $self, $src_type, $src_data ) = @_;
+
+ return $self->NEXT('prepare', $src_type, $src_data )
+ unless $src_type eq 'file';
+
+ my $path = $self->resolve_path($src_data);
+ return $self->NEXT('prepare', 'file' => $path, source_file => $path );
}
sub resolve_path {
- my ($self, $src_data) = @_;
+ my ($self, $src_data) = @_;
- my $current = $self->{source_file};
- my $rootdir = $self->template_root();
+ my $current = $self->{source_file};
+ my $rootdir = $self->template_root();
+
+ my $base = File::Spec->file_name_is_absolute($src_data) ||
+ ! $current ? $rootdir : ( File::Spec->splitpath( $current ) )[1];
- my $base = File::Spec->file_name_is_absolute($src_data) || ! $current
- ? $rootdir
- : ( File::Spec->splitpath( $current ) )[1];
-
- return File::Spec->catfile( $base, $src_data );
+ return File::Spec->catfile( $base, $src_data );
}
sub template_root {
@@ -45,18 +45,19 @@
# $contents = $mason->read_file( $filename );
sub read_file {
- my ( $self, $file ) = @_;
-
- if ( my $root = $self->{strict_root} ) {
-
- $root = $self->template_root if $root eq '1';
- my $path = File::Spec->canonpath( $file );
- # warn "Checking for '$root' in '$path'\n";
- ( $path =~ /\A\Q$root\E(\/|(?<=\/))(?!\.\.)/ )
- or $self->croak_msg("Text::MicroMason::TemplateDir: Template not in required base path '$root'");
- }
-
- return $self->NEXT('read_file', $file );
+ my ( $self, $file ) = @_;
+
+ if ( my $root = $self->{strict_root} ) {
+ $root = $self->template_root if $root eq '1';
+ my $path = Cwd::abs_path($file);
+ my $root_path = Cwd::abs_path($root)
+ or $self->croak_msg("Text::MicroMason::TemplateDir: Strict root '$root' doesn't seem to exist");
+ # warn "Checking for '$root_path' in '$path' (file $file)\n";
+ ( $path =~ /\A\Q$root_path\E/)
+ or $self->croak_msg("Text::MicroMason::TemplateDir: Template '$path' not in required base path '$root_path'");
+ }
+
+ return $self->NEXT('read_file', $file );
}
######################################################################
@@ -137,7 +138,16 @@
=item *
-Text::MicroMason::TemplatePath: Template not in required base path '%s'
+Text::MicroMason::TemplateDir: Strict root '%s' doesn't seem to exist
+
+The strict_root directory (or template_root if strict_root is '1')
+doesn't seem to exist. Strict root checking uses Cwd's abs_path(), and
+requires the strict_root directory to exist at the time the check is
+performed.
+
+=item *
+
+Text::MicroMason::TemplatePath: Template '%s' not in required base path '%s'
The template found in the configured template path was not within the
configured strict_root directory. This may be caused by requesting an
Modified: branches/upstream/libtext-micromason-perl/current/t/08-errors.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-micromason-perl/current/t/08-errors.t?rev=47058&op=diff
==============================================================================
--- branches/upstream/libtext-micromason-perl/current/t/08-errors.t (original)
+++ branches/upstream/libtext-micromason-perl/current/t/08-errors.t Thu Nov 12 04:05:00 2009
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
-use Test::More tests => 6;
+use Test::More tests => 29;
use Text::MicroMason;
my $m = Text::MicroMason->new( );
@@ -24,3 +24,36 @@
}
######################################################################
+
+{
+ my $scr_mobj = <<EOT;
+Hello world!
+This <% thing( %> is a test.
+End.
+EOT
+
+ is eval { $m->compile( text => $scr_mobj ); 1 }, undef, "template with error dies";
+ ok my @lines = split(/\n/, $@), 'multiline output in $@';
+ like shift @lines, qr{MicroMason compilation failed: syntax error at text template \(compiled at t/08-errors.t line \d+\) line 8},
+ 'first line of $@ describes the error location'
+ or diag $@;
+ like shift @lines, qr/^$/, 'second line of $@ is blank'
+ or diag $@;
+
+ like $lines[0], qr{ 0 # line 1 "text template \(compiled at t/08-errors.t line }, 'third line of $@ has a #line'
+ or diag $@;
+
+ like pop @lines, qr{\s+eval \{\.\.\.\} called at t/08-errors.t line \d+}, 'last line of $@ has line number too'
+ or diag $@;
+
+ like pop @lines, qr{\s+at t/08-errors.t line \d+}, 'second to last line of $@ has line number too'
+ or diag $@;
+ like pop @lines, qr{\Q** Please use Text::MicroMason->new(-LineNumbers) for better diagnostics!}
+ or diag $@;
+
+ my $n = 0;
+ foreach my $line (@lines) {
+ like $line, qr/^\s*$n\s+/ or diag $@;
+ $n++;
+ }
+}
More information about the Pkg-perl-cvs-commits
mailing list