Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Perl-Critic CPAN distribution.

Report information
The Basics
Id: 27008
Status: resolved
Priority: 0/
Queue: Test-Perl-Critic

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

Bug Information
Severity: Important
Broken in:
  • 0.02
  • 0.03
  • 0.03_01
  • 0.04
  • 0.05
  • 0.06
  • 0.07
  • 0.08
  • 1.01
Fixed in: (no value)



Subject: Can't set severity
Using Test::Perl::Critic 1.01 with perl 5.8.6 on darwin 8.9.1 (MacOSX 10.4.9): If you want your critic.t to play nice in the absence of Test::Perl::Critic, you have to: eval { require Test::Perl::Critic; }; rather than: eval { use Test::Perl::Critic; }; which will fail in the absence of the module being installed, or: eval " use Test::Perl::Critic; "; which is against the ProhibitStringyEval policy. However, the only way that you can specify a severity setting is when using a use statement, as in: use Test::Perl::Critic(-severity => 5); because passing in an argument when including a module via require will fail: eval { require Test::Perl::Critic(-severity => 5); }; gives: whitbread 1026 % perl -wc t/critic.t syntax error at t/critic.t line 17, near "require Test::Perl::Critic" BEGIN not safe after errors--compilation aborted at t/critic.t line 19. Thus, there is a catch 22 - you want to 'require' it to play nice, but you can't pass in the severity in the require, so you have to 'use' it, but to do so you have to violate a policy! Adding a method to allow setting of the severity would solve the conundrum.
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Thu, 17 May 2007 09:20:30 -0700 (PDT)
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeffrey_thalhammer [...] yahoo.com>
Yeah, I agree that the pragma interface is at odds with loading modules for optional tests. It isn't very pretty, but I think the typical way to handle it is something like this: #----------------------------------------------------- use strict; use warnings; use English qw( -no_match_vars ); use Test::More; eval { require Test::Perl::Critic; }; plan skip_all => 'Test::Perl::Critic required to criticise code' if $EVAL_ERROR; #----------------------------------------------------- Test::Perl::Critic->import( -severity => 2 ); all_critic_ok(); ____________________________________________________________________________________Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sat, 26 May 2007 19:35:47 -0700
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Gavin Sherlock <sherlock [...] genome.stanford.edu>
Thanks - that works, though is a little less intuitive. Adding something to the docs would be good. Also, as I couldn't import the all_perl_files() function in either an eval'd use statement, or in a require, I had to: Perl::Critic::Utils->import(qw(all_perl_files)); to pull in that function. Cheers, Gavin On May 17, 2007, at 9:23 AM, Jeffrey Thalhammer via RT wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=27008 > > > Yeah, I agree that the pragma interface is at odds > with loading modules for optional tests. It isn't > very pretty, but I think the typical way to handle it > is something like this: > > #----------------------------------------------------- > > use strict; > use warnings; > use English qw( -no_match_vars ); > use Test::More; > > eval { require Test::Perl::Critic; }; > plan skip_all => 'Test::Perl::Critic required to > criticise code' if $EVAL_ERROR; > > #----------------------------------------------------- > > Test::Perl::Critic->import( -severity => 2 ); > all_critic_ok(); > > > > > > > ______________________________________________________________________ > ______________Be a better Heartthrob. Get better relationship > answers from someone who knows. Yahoo! Answers - Check it out. > http://answers.yahoo.com/dir/?link=list&sid=396545433
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sat, 26 May 2007 23:10:36 -0700 (PDT)
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeffrey_thalhammer [...] yahoo.com>
Show quoted text
> Also, as I couldn't import the all_perl_files() > function in either an > eval'd use statement, or in a require, I had to: > > Perl::Critic::Utils->import(qw(all_perl_files)); > > to pull in that function.
As you can see, all_perl_files() is provided by Perl::Critic::Utils, not by Test::Perl::Critic. So I'm not really sure what you're expecting to happen. This works fine for me: eval {use Perl::Critic::Utils qw(all_perl_files)}; all_perl_files( '/some/directory' ); Can you send me a file that demonstates the problem? Thanks. -Jeff Show quoted text
____________________________________________________________________________________ We won't tell. Get more on shows you hate to love (and love to hate): Yahoo! TV's Guilty Pleasures list. http://tv.yahoo.com/collections/265
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sun, 27 May 2007 07:49:27 -0500
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On May 27, 2007, at 1:11 AM, Jeffrey Thalhammer via RT wrote: Show quoted text
> This works fine for me: > > eval {use Perl::Critic::Utils qw(all_perl_files)}; > all_perl_files( '/some/directory' );
Jeff, that doesn't work. "use" happens at compile time, so the eval {} is irrelevant. You have to employ "require". % perl -e'BEGIN{@INC=()} eval{use Test::Perl::Critic}' Can't locate Test/Perl/Critic.pm in @INC (@INC contains:) at -e line 1. BEGIN failed--compilation aborted at -e line 1. Chris -- Chris Dolan, Equilibrious LLC, http://equilibrious.net/ Public key: http://chrisdolan.net/public.key vCard: http://chrisdolan.net/ChrisDolan.vcf
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sun, 27 May 2007 07:49:27 -0500
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On May 27, 2007, at 1:11 AM, Jeffrey Thalhammer via RT wrote: Show quoted text
> This works fine for me: > > eval {use Perl::Critic::Utils qw(all_perl_files)}; > all_perl_files( '/some/directory' );
Jeff, that doesn't work. "use" happens at compile time, so the eval {} is irrelevant. You have to employ "require". % perl -e'BEGIN{@INC=()} eval{use Test::Perl::Critic}' Can't locate Test/Perl/Critic.pm in @INC (@INC contains:) at -e line 1. BEGIN failed--compilation aborted at -e line 1. Chris -- Chris Dolan, Equilibrious LLC, http://equilibrious.net/ Public key: http://chrisdolan.net/public.key vCard: http://chrisdolan.net/ChrisDolan.vcf
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sun, 27 May 2007 07:49:27 -0500
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On May 27, 2007, at 1:11 AM, Jeffrey Thalhammer via RT wrote: Show quoted text
> This works fine for me: > > eval {use Perl::Critic::Utils qw(all_perl_files)}; > all_perl_files( '/some/directory' );
Jeff, that doesn't work. "use" happens at compile time, so the eval {} is irrelevant. You have to employ "require". % perl -e'BEGIN{@INC=()} eval{use Test::Perl::Critic}' Can't locate Test/Perl/Critic.pm in @INC (@INC contains:) at -e line 1. BEGIN failed--compilation aborted at -e line 1. Chris -- Chris Dolan, Equilibrious LLC, http://equilibrious.net/ Public key: http://chrisdolan.net/public.key vCard: http://chrisdolan.net/ChrisDolan.vcf
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sun, 27 May 2007 07:32:29 -0700
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Gavin Sherlock <sherlock [...] genome.stanford.edu>
Yep - I should have been more specific. I was trying to say that I couldn't eval it and pull in the all_perl_files function, without it failing on machines without Perl::Critic installed, but that I can't pull the function in with a require, thus needing an import statement instead. Cheers, Gavin On May 27, 2007, at 6:01 AM, Chris Dolan via RT wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=27008 > > > On May 27, 2007, at 1:11 AM, Jeffrey Thalhammer via RT wrote: >
>> This works fine for me: >> >> eval {use Perl::Critic::Utils qw(all_perl_files)}; >> all_perl_files( '/some/directory' );
> > Jeff, that doesn't work. "use" happens at compile time, so the eval > {} is irrelevant. You have to employ "require". > > % perl -e'BEGIN{@INC=()} eval{use Test::Perl::Critic}' > Can't locate Test/Perl/Critic.pm in @INC (@INC contains:) at -e > line 1. > BEGIN failed--compilation aborted at -e line 1. > > Chris > > > -- > Chris Dolan, Equilibrious LLC, http://equilibrious.net/ > Public key: http://chrisdolan.net/public.key > vCard: http://chrisdolan.net/ChrisDolan.vcf > > >
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sun, 27 May 2007 07:49:27 -0500
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On May 27, 2007, at 1:11 AM, Jeffrey Thalhammer via RT wrote: Show quoted text
> This works fine for me: > > eval {use Perl::Critic::Utils qw(all_perl_files)}; > all_perl_files( '/some/directory' );
Jeff, that doesn't work. "use" happens at compile time, so the eval {} is irrelevant. You have to employ "require". % perl -e'BEGIN{@INC=()} eval{use Test::Perl::Critic}' Can't locate Test/Perl/Critic.pm in @INC (@INC contains:) at -e line 1. BEGIN failed--compilation aborted at -e line 1. Chris -- Chris Dolan, Equilibrious LLC, http://equilibrious.net/ Public key: http://chrisdolan.net/public.key vCard: http://chrisdolan.net/ChrisDolan.vcf
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sun, 27 May 2007 13:44:46 -0700 (PDT)
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeffrey_thalhammer [...] yahoo.com>
Yes, that's correct. I must have been thinking of: eval {'use Perl::Critic::Utils qw(all_perl_files)'}; which is forbidden by ProhibitStringyEval. Sometimes I forget to eat my own dog food :) My bad. -Jeff --- Chris Dolan via RT <bug-Test-Perl-Critic@rt.cpan.org> wrote: Show quoted text
> > Queue: Test-Perl-Critic > Ticket <URL: > http://rt.cpan.org/Ticket/Display.html?id=27008 > > > On May 27, 2007, at 1:11 AM, Jeffrey Thalhammer via > RT wrote: >
> > This works fine for me: > > > > eval {use Perl::Critic::Utils
> qw(all_perl_files)};
> > all_perl_files( '/some/directory' );
> > Jeff, that doesn't work. "use" happens at compile > time, so the eval > {} is irrelevant. You have to employ "require". > > % perl -e'BEGIN{@INC=()} eval{use > Test::Perl::Critic}' > Can't locate Test/Perl/Critic.pm in @INC (@INC > contains:) at -e line 1. > BEGIN failed--compilation aborted at -e line 1. > > Chris
Show quoted text
____________________________________________________________________________________ Food fight? Enjoy some healthy debate in the Yahoo! Answers Food & Drink Q&A. http://answers.yahoo.com/dir/?link=list&sid=396545367
Subject: Re: [rt.cpan.org #27008] Can't set severity
Date: Sun, 27 May 2007 18:16:51 -0500
To: bug-Test-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On May 27, 2007, at 9:35 AM, sherlock@genome.stanford.edu via RT wrote: Show quoted text
> > Queue: Test-Perl-Critic > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=27008 > > > Yep - I should have been more specific. I was trying to say that I > couldn't eval it and pull in the all_perl_files function, without it > failing on machines without Perl::Critic installed, but that I can't > pull the function in with a require, thus needing an import statement > instead. > > Cheers, > Gavin
Ahh, I see. Then what you want is: eval { require Test::Perl::Critic; Test::Perl::Critic->import; } because behind the scenes use Foo::Bar qw(baz); is (nearly) equivalent to BEGIN { require Foo::Bar; Foo::Bar->import(qw(baz)); } The only difference is the special case of use Foo::Bar 1.23; which enforces a version number. Chris -- Chris Dolan, Equilibrious LLC, http://equilibrious.net/ Public key: http://chrisdolan.net/public.key vCard: http://chrisdolan.net/ChrisDolan.vcf