Skip Menu |

This queue is for tickets about the Scalar-Andand CPAN distribution.

Report information
The Basics
Id: 54775
Status: resolved
Priority: 0/
Queue: Scalar-Andand

People
Owner: LEONT [...] cpan.org
Requestors: norbi [...] nix.hu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.03
Fixed in: 0.04



Subject: class method calls on variables elicit warnings
When Scalar::Andand is loaded, the 'syntax' warnings is enabled (enabled by default with "use warnings;") and a class method is called on a variable (ie. the variable contains a non-ref scalar), Perl emits a warning: mendel@vger:~$ perl -we 'use Scalar::Andand; my $x = "Foo"; $x->new; package Foo; sub new { bless {} };' Can't locate package Scalar::Andand::Scalar for @autobox::shim::<1>::ISA at -e line 1. Can't locate package Scalar::Andand::Scalar for @autobox::shim::<1>::ISA at -e line 1. mendel@vger:~$ See the attached patch (tests included).
Subject: Scalar-Andand-class_method_warning-fix.diff
diff -Naur a/Scalar-Andand-0.03/Build.PL b/Scalar-Andand-0.03/Build.PL --- a/Scalar-Andand-0.03/Build.PL 2009-01-08 21:28:52.000000000 +0100 +++ b/Scalar-Andand-0.03/Build.PL 2010-02-18 21:35:34.000000000 +0100 @@ -8,7 +8,9 @@ dist_author => 'Leon Timmermans <leont@cpan.org>', dist_version_from => 'lib/Scalar/Andand.pm', build_requires => { - 'Test::More' => 0, + 'Test::More' => 0, + 'Test::Exception' => 0, + 'Test::Warn' => 0, }, requires => { 'autobox::Core' => 0, diff -Naur a/Scalar-Andand-0.03/lib/Scalar/Andand.pm b/Scalar-Andand-0.03/lib/Scalar/Andand.pm --- a/Scalar-Andand-0.03/lib/Scalar/Andand.pm 2009-01-08 21:28:52.000000000 +0100 +++ b/Scalar-Andand-0.03/lib/Scalar/Andand.pm 2010-02-18 21:55:37.000000000 +0100 @@ -26,6 +26,8 @@ return $noop; } +package Scalar::Andand::Scalar; + 1; __END__ diff -Naur a/Scalar-Andand-0.03/t/11-class_methods.t b/Scalar-Andand-0.03/t/11-class_methods.t --- a/Scalar-Andand-0.03/t/11-class_methods.t 1970-01-01 01:00:00.000000000 +0100 +++ b/Scalar-Andand-0.03/t/11-class_methods.t 2010-02-18 21:59:52.000000000 +0100 @@ -0,0 +1,50 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 8; +use Test::Exception; +use Test::Warn; +use Scalar::Andand; + +warnings_are { + lives_and { + my $existing_pkg = 'Tester'; + + ok($existing_pkg->new->isa('Tester')); + } "\$existing_pkg->new() calls the class method"; +} [], "\$existing_pkg->new() does not warn"; + +warnings_are { + lives_and { + my $existing_pkg = 'Tester'; + + ok($existing_pkg->andand->new->isa('Tester')); + } "\$existing_pkg->andand->new() calls the class method"; +} [], "\$existing_pkg->andand->new() does not warn"; + +warnings_are { + throws_ok { + my $nonexistent_pkg = 'Non::Existent::Package'; + + $nonexistent_pkg->new; + } qr/^Can't locate object method "new" via package "Non::Existent::Package"/, + "\$nonexistent_pkg->new() throws the right exception"; +} [], "\$nonexistent_pkg->new() does not warn"; + +warnings_are { + throws_ok { + my $nonexistent_pkg = 'Non::Existent::Package'; + + $nonexistent_pkg->andand->new; + } qr/^Can't locate object method "new" via package "Non::Existent::Package"/, + "\$nonexistent_pkg->andand->new() throws the right exception"; +} [], "\$nonexistent_pkg->andand->new() does not warn"; + + +package Tester; + +sub new { + return bless {}; +}
From: norbi [...] nix.hu
I forgot to tell my perl and autobox.pm versions: perl: v5.10.0 built for i486-linux-gnu-thread-multi (from Debian Lenny) autobox: 2.55
Hi Norbert, Thanks for the patch. It has been applied and a new version has been released to CPAN. Regards, Leon