Skip Menu |

This queue is for tickets about the Template-Plugin-Cycle CPAN distribution.

Report information
The Basics
Id: 8901
Status: resolved
Worked: 45 min
Priority: 0/
Queue: Template-Plugin-Cycle

People
Owner: adamk [...] cpan.org
Requestors: dave [...] dave.org.uk
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Fixes to make Template::Plugin::Cycle a real TT Plugin
Adam, As discussed on use.perl, your module as it stands isn't really a TT plugin as it doesn't follow the TT plugin architecture. This actually turns out to be a really simple fix. You just need to inherit from Template::Plugin and then deal with an extra parameter (the TT context) in your constructor. In your case (in most cases in my experience) you can simply ignore the context argument to the constructor - but you need to remove it from @_ before processing your real arguments. The first part of the patch file attached deals with fixing up Cycle.pm. But there is then a problem with the tests. TT plugins aren't really meant to be be called from Perl programs. They are just their to be called from within templates. Which means that you can't easily test them with "normal" test plans. The most obvious problem is that the "new" method expects this extra context argument that I mentioned above. So most of the tests in your 02_main.t were failing when I applied my patch. The second half of the patch file fixes that. Well, it doesn't so much fix it as works around it. I've added a fake (undef) context argument to all of the "new" calls. This only works because I know that we never use the context argument. Really you should be testing the plugin from within TT. You can use a homemade solution as I did in Template::Plugin::Audiofile::Info or alternatively there's a Template::Test module that's part of the TT distribution. I'd be happy to work with you on fixing up the test plan if you're interested. Hope this is useful. Dave...
--- lib/Template/Plugin/Cycle.pm.orig 2004-12-15 08:32:27.381506925 +0000 +++ lib/Template/Plugin/Cycle.pm 2004-12-15 08:43:54.665912753 +0000 @@ -89,6 +89,8 @@ use overload 'bool' => sub () { 1 }; use overload '""' => 'next'; +use base qw{Template::Plugin}; + use vars qw{$VERSION}; BEGIN { $VERSION = '0.01'; @@ -113,6 +115,7 @@ sub new { my $self = bless [ 0, () ], shift; + my $context = shift; $self->init( @_ ) if @_; $self; } --- t/02_main.t.orig 2004-12-15 08:48:10.223789879 +0000 +++ t/02_main.t 2004-12-15 08:45:42.194872950 +0000 @@ -44,7 +44,7 @@ ); # Additional custom instance-specific tests -my @Cycles = map { Template::Plugin::Cycle->new( @{$_->[0]} ) } @test_data; +my @Cycles = map { Template::Plugin::Cycle->new( undef, @{$_->[0]} ) } @test_data; ok( @Cycles == 4, "Four test items in test array" ); # Do some specific tests on the null form @@ -65,7 +65,7 @@ # Do some basic tests on each cycle foreach my $data ( @test_data ) { my $params = $data->[0]; - my $Cycle = Template::Plugin::Cycle->new( @$params ); + my $Cycle = Template::Plugin::Cycle->new( undef, @$params ); ok( $Cycle, 'A cycle object is boolean true' ); isa_ok( $Cycle, TPC ); my $Cycle2 = Template::Plugin::Cycle->new();