Skip Menu |

This queue is for tickets about the UNIVERSAL-can CPAN distribution.

Report information
The Basics
Id: 17527
Status: resolved
Worked: 1.5 hours (90 min)
Priority: 0/
Queue: UNIVERSAL-can

People
Owner: chromatic [...] cpan.org
Requestors: BADGERSRC [...] cpan.org
Cc: abw [...] wardley.org
markdclements [...] yahoo.co.uk
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.03
Fixed in: (no value)



CC: abw [...] wardley.org,markdclements [...] yahoo.co.uk
Subject: causes silent failure in Template toolkit
I have been seeing strange behaviour when using Test::MockObject and Template Toolkit, although I haven't been mocking TT objects. I've tracked the issue down to an interaction between UNIVERSAL::can and TT. In summary, TT does not produce any output with the following test case (although it does under UNIVERSAL::can 1.00): X:\work\justice\migration>cat template.t use strict; use warnings; use Template; use UNIVERSAL::can; use constant TEMPLATEFILE => q(template.tt); my $template = Template->new( ); $template->process( TEMPLATEFILE , {} ) or die $template->error; X:\work\justice\migration>perl template.t (and then having commented out "use UNIVERSAL::can". X:\work\justice\migration>perl template.t this is output X:\work\justice\migration>cat template.tt this is output X:\work\justice\migration> Parts of TT can be trivially fixed to work under UNIVERSAL::can, but, to quote Andy Wardley (cc'ed, co-author of TT): The UNIVERSAL::can() call is used in many places in TT and in some of those places it absolutely has to work as advertised in the Perl core and not in any other way Further discussion can be seen at: http://rt.cpan.org/Ticket/Display.html?id=17503 It would be very useful (to me, at least) if Test::MockObject and TT could be made to work together. regards, Mark
Subject: Re: [rt.cpan.org #17527] causes silent failure in Template toolkit
Date: Wed, 8 Feb 2006 12:18:14 -0800
To: bug-UNIVERSAL-can [...] rt.cpan.org
From: chromatic <chromatic [...] wgz.org>
On Tuesday 07 February 2006 23:19, via RT wrote: Show quoted text
> I have been seeing strange behaviour when using Test::MockObject and > Template Toolkit, although I haven't been mocking TT objects. I've > tracked the issue down to an interaction between UNIVERSAL::can and TT. > > In summary, TT does not produce any output with the following test case > (although it does under UNIVERSAL::can 1.00): > > X:\work\justice\migration>cat template.t > use strict; > use warnings; > > use Template; > use UNIVERSAL::can; > > use constant TEMPLATEFILE => q(template.tt); > my $template = Template->new( ); > > $template->process( TEMPLATEFILE , {} ) or die $template->error; > > > X:\work\justice\migration>perl template.t > > (and then having commented out "use UNIVERSAL::can". > > X:\work\justice\migration>perl template.t > this is output > > X:\work\justice\migration>cat template.tt > this is output > > X:\work\justice\migration>
Good catch. Show quoted text
> It would be very useful (to me, at least) if Test::MockObject and TT > could be made to work together.
Agreed. The fix to TT is to change the line in Template::Provider: elsif (UNIVERSAL::can($dir, 'paths')) { ... to: elsif ( eval { $dir->can( 'paths' ) } ) { ... but there is a legitimate bug in UNIVERSAL::can 1.03 that doesn't check that the apparent invocant is a legitimate class or object. I've found a hacky fix and will clean it up and publish version 1.04 soon. In the meantime, you can work around the problem by editing UNIVERSAL::can::can() to add the statements: unless ( eval { $_[0]->isa( 'UNIVERSAL' ) } ) { _report_warning(); goto &$orig; } ... immediately after the line: goto &$orig if $can == \&UNIVERSAL::can; Thanks for the report! -- c
Subject: Re: [rt.cpan.org #17527] causes silent failure in Template toolkit
Date: Thu, 9 Feb 2006 12:57:55 +0000 (GMT)
To: bug-UNIVERSAL-can [...] rt.cpan.org
From: Mark Clements <markdclements [...] yahoo.co.uk>
--- "chromatic@wgz.org via RT" <bug-UNIVERSAL-can@rt.cpan.org> wrote: Show quoted text
> > ... but there is a legitimate bug in UNIVERSAL::can 1.03 that doesn't check > that the apparent invocant is a legitimate class or object. I've found a > hacky fix and will clean it up and publish version 1.04 soon. In the > meantime, you can work around the problem by editing UNIVERSAL::can::can() to > add the statements: > > unless ( eval { $_[0]->isa( 'UNIVERSAL' ) } ) > { > _report_warning(); > goto &$orig; > } > > ... immediately after the line: > > goto &$orig if $can == \&UNIVERSAL::can;
Thanks for looking at this. Unfortunately that particular fix doesn't help my situation much: (having applied the workaround) mark:~/work/justice/migration$ cat cgimock.t use strict; use warnings; use CGI; use Test::MockObject::Extends; my $mocked = Test::MockObject::Extends->new( CGI->new ); mark:~/work/justice/migration$ perl cgimock.t Deep recursion on subroutine "UNIVERSAL::isa" at /home/perl/lib/UNIVERSAL/can.pm line 38. mark:~/work/justice/migration$ Though for the moment I can just apply your recommended modification to TT. Show quoted text
> Thanks for the report!
Again, thanks for the quick feedback. regards, Mark
Subject: Re: [rt.cpan.org #17527] causes silent failure in Template toolkit
Date: Thu, 9 Feb 2006 18:01:52 -0800
To: bug-UNIVERSAL-can [...] rt.cpan.org
From: chromatic <chromatic [...] wgz.org>
On Thursday 09 February 2006 04:58, markdclements@yahoo.co.uk via RT wrote: Show quoted text
> Thanks for looking at this. Unfortunately that particular fix doesn't help > my situation much: > > (having applied the workaround) > > mark:~/work/justice/migration$ cat cgimock.t > use strict; > use warnings; > > use CGI; > use Test::MockObject::Extends; > > > my $mocked = Test::MockObject::Extends->new( CGI->new ); > mark:~/work/justice/migration$ perl cgimock.t > Deep recursion on subroutine "UNIVERSAL::isa" at > /home/perl/lib/UNIVERSAL/can.pm line 38. > > mark:~/work/justice/migration$
Ah yes. I released 1.10, then tested against this and realized why this didn't work. Version 1.11 should fix it. Thanks again!, -- c