Skip Menu |

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

Report information
The Basics
Id: 48642
Status: resolved
Priority: 0/
Queue: Template-Declare

People
Owner: Nobody in particular
Requestors: dolmen [...] cpan.org
Cc:
AdminCc:

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

Attachments
Template-Declare-0.40-SARTAK-RT48642.patch



Subject: Can't use inline TagSet (embedded package)
Template::Declare::Tags loads a module with "eval use" without testing if the module is already loaded. This is a problem when locally defining a TagSet module using lexical scoping, so without a '.pm' file. How to fix it: in TagSet->inmport(), check $module->can('new') before trying to 'eval "use $module"'. If it success, it means the module is already available so "eval use" can be skipped. Package lexical scoping is useful for examples and perlmonks.org postings ;^)
Subject: Re: [rt.cpan.org #48642] Can't use inline TagSet (embedded package)
Date: Wed, 12 Aug 2009 11:39:20 +0100
To: Olivier 'dolmen' Mengué via RT <bug-Template-Declare [...] rt.cpan.org>
From: Jesse Vincent <jesse [...] fsck.com>
I'd happily take a patch with the fix and some good tests. Thanks! On Wed 12.Aug'09 at 5:36:49 -0400, Olivier 'dolmen' Mengué via RT wrote: Show quoted text
> Wed Aug 12 05:36:48 2009: Request 48642 was acted upon. > Transaction: Ticket created by DOLMEN > Queue: Template-Declare > Subject: Can't use inline TagSet (embedded package) > Broken in: 0.40 > Severity: Normal > Owner: Nobody > Requestors: dolmen@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=48642 > > > > Template::Declare::Tags loads a module with "eval use" without testing > if the module is already loaded. This is a problem when locally defining > a TagSet module using lexical scoping, so without a '.pm' file. > > How to fix it: in TagSet->inmport(), check $module->can('new') before > trying to 'eval "use $module"'. If it success, it means the module is > already available so "eval use" can be skipped. > > Package lexical scoping is useful for examples and perlmonks.org > postings ;^) >
Subject: [PATCH] Can't use inline TagSet (embedded package)
Show quoted text
> I'd happily take a patch with the fix and some good tests.
Here is the full patch, including the test. By the way, thank you for your presentation about sd at Lisbon. You made me discover Shipwright and that alone was enough to be glad to be there.
# RT48642 Can't use inline TagSet (embedded package) # # To apply this patch: # STEP 1: Chdir to the source directory. # STEP 2: Run the 'applypatch' program with this patch file as input. # # If you do not have 'applypatch', it is part of the 'makepatch' package # that you can fetch from the Comprehensive Perl Archive Network: # http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz # In the above URL, 'x' should be 2 or higher. # # To apply this patch without the use of 'applypatch': # STEP 1: Chdir to the source directory. # If you have a decent Bourne-type shell: # STEP 2: Run the shell with this file as input. # If you don't have such a shell, you may need to manually create # the files as shown below. # STEP 3: Run the 'patch' program with this file as input. # # These are the commands needed to create/delete files/directories: # touch "t/inline-tagset.t" chmod 0666 "t/inline-tagset.t" # # This command terminates the shell and need not be executed manually. exit # #### End of Preamble #### #### Patch data follows #### diff -urp --binary "Template-Declare-0.40\MANIFEST" "Template-Declare-0.40.RT48642\MANIFEST" Index: ./MANIFEST --- ./MANIFEST Wed Jul 8 22:23:48 2009 +++ ./MANIFEST Wed Aug 12 13:48:55 2009 @@ -39,6 +39,7 @@ t/forms.t t/importing.t t/indent.t t/indexhtml.t +t/inline-tagset.t t/instrumentation.t t/MyTagSet.pm t/namespace.t diff -urp --binary "Template-Declare-0.40\lib\Template\Declare\Tags.pm" "Template-Declare-0.40.RT48642\lib\Template\Declare\Tags.pm" Index: ./lib/Template/Declare/Tags.pm --- ./lib/Template/Declare/Tags.pm Thu Apr 23 05:28:36 2009 +++ ./lib/Template/Declare/Tags.pm Wed Aug 12 13:44:11 2009 @@ -57,10 +57,12 @@ sub import { "Template::Declare::TagSet::$lang"; ### Loading tag set: $module - eval "use $module"; - if ($@) { - warn $@; - croak "Failed to load tagset module $module"; + if (! $module->can('get_tag_list') ) { + eval "use $module"; + if ($@) { + warn $@; + croak "Failed to load tagset module $module"; + } } ### TagSet options: $opts my $tagset = $module->new($opts); diff -urp --binary nul "Template-Declare-0.40.RT48642\t\inline-tagset.t" Index: ./t/inline-tagset.t --- ./t/inline-tagset.t Thu Jan 1 01:00:00 1970 +++ ./t/inline-tagset.t Wed Aug 12 13:51:54 2009 @@ -0,0 +1,19 @@ +# Test for RT48642 by Olivier Mengué + +use Test::More tests => 1; + +{ + package Template::Declare::TagSet::FooBarBaz; + use base 'Template::Declare::TagSet'; + sub get_tag_list { + [qw/foo bar baz/] + } +} + +eval "use Template::Declare::Tags 'FooBarBaz'"; +my $res = $@; +SKIP: { + skip "T::D::TS::FooBarBaz.pm exists, can't test!" if exists $INC{'Template/Declare/TagSet/FooBarBaz.pm'}; + ok(!$res, "use inline TagSet"); + diag $res if $res; +} #### End of Patch data #### #### ApplyPatch data follows #### # Data version : 1.0 # Date generated : Wed Aug 12 13:51:56 2009 # Generated by : makepatch 2.03 # Recurse directories : Yes # Excluded files : (\A|/).*\~\Z # (\A|/).*\.a\Z # (\A|/).*\.bak\Z # (\A|/).*\.BAK\Z # (\A|/).*\.elc\Z # (\A|/).*\.exe\Z # (\A|/).*\.gz\Z # (\A|/).*\.ln\Z # (\A|/).*\.o\Z # (\A|/).*\.obj\Z # (\A|/).*\.olb\Z # (\A|/).*\.old\Z # (\A|/).*\.orig\Z # (\A|/).*\.rej\Z # (\A|/).*\.so\Z # (\A|/).*\.Z\Z # (\A|/)\.del\-.*\Z # (\A|/)\.make\.state\Z # (\A|/)\.nse_depinfo\Z # (\A|/)core\Z # (\A|/)tags\Z # (\A|/)TAGS\Z # p "MANIFEST" 1330 1250077735 0100666 # p "lib/Template/Declare/Tags.pm" 24026 1250077451 0100666 # c "t/inline-tagset.t" 0 1250077914 0100666 #### End of ApplyPatch data #### #### End of Patch kit [created: Wed Aug 12 13:51:56 2009] #### #### Patch checksum: 93 3214 16054 #### #### Checksum: 123 4280 40372 ####
Subject: Re: [rt.cpan.org #48642] [PATCH] Can't use inline TagSet (embedded package)
Date: Wed, 12 Aug 2009 13:04:51 +0100
To: Olivier 'dolmen' Mengué via RT <bug-Template-Declare [...] rt.cpan.org>
From: Jesse Vincent <jesse [...] fsck.com>
Show quoted text
> Here is the full patch, including the test. > > By the way, thank you for your presentation about sd at Lisbon. You made > me discover Shipwright and that alone was enough to be glad to be there.
My pleasure! Out of curiousity, what tool generated that patchset? I don't recognize the style.
Download (untitled)
application/pgp-signature 194b

Message body not shown because it is not plain text.

Show quoted text
> Out of curiousity, what tool generated that patchset? I don't recognize > the style.
This is JV/makepatch-2.04.tar.gz http://search.cpan.org/dist/makepatch/script/makepatch Glad to learn you something in return ;)
Show quoted text
> Glad to learn you something in return ;)
I have to learn to teach (this is the same word in french).
Subject: Re: [rt.cpan.org #48642] [PATCH] Can't use inline TagSet (embedded package)
Date: Wed, 12 Aug 2009 15:23:07 -0400
To: Olivier 'dolmen' Mengué via RT <bug-Template-Declare [...] rt.cpan.org>
From: Jesse Vincent <jesse [...] fsck.com>
Thanks! Applied locally. It'll be in the 0.40_01 dev release after I land (and appear in svn at about the same time). -jesse On Wed 12.Aug'09 at 8:02:17 -0400, Olivier 'dolmen' Mengué via RT wrote: Show quoted text
> Queue: Template-Declare > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=48642 > >
> > I'd happily take a patch with the fix and some good tests.
> > Here is the full patch, including the test. > > By the way, thank you for your presentation about sd at Lisbon. You made > me discover Shipwright and that alone was enough to be glad to be there.