Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Class-InsideOut CPAN distribution.

Report information
The Basics
Id: 24839
Status: resolved
Priority: 0/
Queue: Class-InsideOut

People
Owner: dagolden [...] cpan.org
Requestors: stanis.trendelenburg [...] pluto.uni-freiburg.de
Cc:
AdminCc:

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



Subject: new() does not accept a hashref as argument
Date: Thu, 08 Feb 2007 10:15:31 +0100
To: bug-Class-InsideOut [...] rt.cpan.org
From: Stanis Trendelenburg <stanis.trendelenburg [...] pluto.uni-freiburg.de>
The check of whether the argument to new() is a hash or a hashref has a bug, which leads to hashrefs not being accepted (it dies with "Arguments to new must be a hash or hash reference"). Patch and test case are attached.
--- lib/Class/InsideOut.pm.orig 2007-02-08 09:50:47.000000000 +0100 +++ lib/Class/InsideOut.pm 2007-02-08 10:09:54.000000000 +0100 @@ -97,7 +97,7 @@ # initialization croak "Arguments to new must be a hash or hash reference" - if ( @_ == 1 && ref($_[0]) && reftype($_[0]) ne 'HASH' ) || ( @_ % 2 ); + if ( @_ == 1 && ref($_[0]) && reftype($_[0]) ne 'HASH' ) || ( @_ > 1 && @_ % 2 ); my %args = (@_ == 1) ? %{$_[0]} : @_;
#!/usr/bin/perl -w use strict; use Test::More tests => 2; use Test::Exception; { package TestClass; use strict; use Class::InsideOut qw( new public ); public name => my %name; } lives_ok( sub { my $obj = TestClass->new( name => 'foo' ) }, "Can pass a hash to new()" ); lives_ok( sub { my $obj = TestClass->new({ name => 'foo' }) }, "Can pass a hash reference to new()" );
Great catch. My test code didn't test what I thought it was testing. Fixed in 1.05, now on the way to CPAN.