It's been an extremely long day (though condensed and compacted) of hacking on Catalyst::Helper.
I mostly worked on a test to check if the file contents of a file created with the now deprecated API were the same as the original helper API, so we could make sure we didn't break anything. 2/3 tests pass, but this last one is being absolutely heinous.
Here's some example code:
I mostly worked on a test to check if the file contents of a file created with the now deprecated API were the same as the original helper API, so we could make sure we didn't break anything. 2/3 tests pass, but this last one is being absolutely heinous.
Here's some example code:
sub render_file {This is the render_file method broken up into the new API and the backwards compatible API. I'm having an issue with this test, however:
my ( $self, $file, $path, $vars ) = @_;
my $template = $self->get_file( ( caller(0) )[0], $file );
$self->render_file_contents($self, $template, $path, $vars);
}
sub render_sharedir_file {
my ( $self, $file, $path, $vars ) = @_;
my $template = $self->get_sharedir_file( $file );
$self->render_file_contents($self, $template, $path, $vars);
}
sub render_file_contents {
my ( $self, $template, $path, $vars ) = @_;
$vars ||= {};
my $t = Template->new;
return 0 unless $template;
my $output;
$t->process( \$template, { %{$self}, %$vars }, \$output )
|| Catalyst::Exception->throw(
message => qq/Couldn't process "$template", / . $t->error() );
$self->mk_file( $path, $output );
}
The first and second tests pass just fine. The third one spits out this nice bit of garbage:
use strict;
use warnings;
use FindBin qw/$Bin/;
use File::Temp qw/tempfile/;
use lib "$Bin/lib";
use Data::Dumper;
use MyTestHelper;
use Test::More tests => 3;
my $helper = bless {}, 'MyTestHelper';
my $example1 = $helper->get_file('MyTestHelper', 'example1');
chomp $example1;
my $example2 = $helper->get_file('MyTestHelper', 'example2');
chomp $example2;
is $example1, 'foobar[% test_var %]';
is $example2, 'bazquux';
my ($fh, $fn) = tempfile;
$helper->render_file($fn, { test_var => 'test_val' });
seek $fh, 0, 0; # Rewind
my $contents;
{
local $/;
$contents = <$fh>;
}
warn $contents;
is $contents, 'foobartest_val';
devin@devin-laptop:~/web-devel/Catalyst-Devel/1.00/branches/helper_refactor$ prove -l t/back_compat.tBasically, it's telling me it doesn't like this line:
t/back_compat.t .. 1/3 readline() on unopened filehandle DATA at (eval 226) line 1.
Use of uninitialized value $data in split at /home/devin/web-devel/Catalyst-Devel/1.00/branches/helper_refactor/lib/Catalyst/Helper.pm line 59.
Couldn't process "MyTestHelper=HASH(0xcccdf0)", Not a GLOB reference at /usr/local/lib/perl/5.10.0/Template/Provider.pm line 618.
at t/back_compat.t line 25
# Looks like you planned 3 tests but ran 2.
# Looks like your test exited with 2 just after 2.
t/back_compat.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 1/3 subtests
Test Summary Report
-------------------
t/back_compat.t (Wstat: 512 Tests: 2 Failed: 0)
Non-zero exit status: 2
Parse errors: Bad plan. You planned 3 tests but ran 2.
Files=1, Tests=2, 1 wallclock secs ( 0.04 usr 0.00 sys + 0.47 cusr 0.05 csys = 0.56 CPU)
Result: FAIL
Why? I've yet to figure it out. More head pounding is on the way.
$helper->render_file($fn, { test_var => 'test_val' });







Leave a comment