Skip Menu |

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

Report information
The Basics
Id: 13964
Status: open
Priority: 0/
Queue: Class-Std

People
Owner: Nobody in particular
Requestors: dan.kubb-cpan [...] autopilotmarketing.com
Cc:
AdminCc:

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



Subject: Bug in Class::Std CUMULATIVE methods using shift(@_)
There is a bug in how Class::Std handles CUMULATIVE methods that use shift on @_. There's an idiom I use sometimes that revealed the problem: sub method { shift->other_method('extra_info_to_pass_in' => @_) } When Class::Std dispatches to two or more methods, the @_ is modified by the shift, so the second method will not get $self when shifting, but will instead get $_[1]. Attached is a failing test case that demonstraits the problem. It must be applied AFTER the patch I submitted for bug 13962 is applied.
--- t/cumulative.t~ 2005-08-01 13:42:04.000000000 -0700 +++ t/cumulative.t 2005-08-01 13:43:10.000000000 -0700 @@ -4,6 +4,7 @@ { sub base_first :CUMULATIVE(BASE FIRST) { return __PACKAGE__ } sub der_first :CUMULATIVE { return __PACKAGE__ } + sub shift_obj :CUMULATIVE { return shift } } package Base2; @@ -11,6 +12,7 @@ { sub base_first :CUMULATIVE(BASE FIRST) { return __PACKAGE__ } sub der_first :CUMULATIVE { return __PACKAGE__ } + sub shift_obj :CUMULATIVE { return shift } } package Base3; @@ -19,6 +21,7 @@ { sub base_first :CUMULATIVE(BASE FIRST) { return __PACKAGE__ } sub der_first :CUMULATIVE { return __PACKAGE__ } + sub shift_obj :CUMULATIVE { return shift } } package Base4; @@ -26,6 +29,7 @@ { sub base_first { return __PACKAGE__ } sub der_first { return __PACKAGE__ } + sub shift_obj { return shift } } package Der1; @@ -34,6 +38,7 @@ { sub base_first :CUMULATIVE(BASE FIRST) { return __PACKAGE__ } sub der_first :CUMULATIVE { return __PACKAGE__ } + sub shift_obj :CUMULATIVE { return shift } } package Der2; @@ -42,6 +47,7 @@ { sub base_first :CUMULATIVE(BASE FIRST) { return __PACKAGE__ } sub der_first :CUMULATIVE { return __PACKAGE__ } + sub shift_obj :CUMULATIVE { return shift } } package Reder1; @@ -50,11 +56,12 @@ { sub base_first :CUMULATIVE(BASE FIRST) { return __PACKAGE__ } sub der_first :CUMULATIVE { return __PACKAGE__ } + sub shift_obj :CUMULATIVE { return shift } } package main; -use Test::More tests => 60; +use Test::More tests => 62; my $obj = Reder1->new(); @@ -64,9 +71,12 @@ my $up_string = join q{}, @up_order; my $down_string = join q{}, @down_order; +my @objs = ($obj) x 6; + for my $test_run (1..2) { my $res_up = $obj->der_first(); my $res_down = $obj->base_first(); + my $res_objs = $obj->shift_obj(); is int $res_up, int @up_order => 'Numeric cumulative up'; is int $res_down, int @down_order => 'Numeric cumulative down'; @@ -86,4 +96,6 @@ ok grep($classname, @down_order) => "Valid down hash key ($classname)"; is $classname, $res_up->{$classname} => "Valid down hash value ($classname)"; } + + is_deeply \@$res_objs, \@objs => "shift(\@_) used in method"; }
From: Dan Kubb <dan.kubb [...] autopilotmarketing.com>
Subject: Re: [cpan #13964]
Date: Mon, 1 Aug 2005 14:00:48 -0700
To: bug-Class-Std [...] rt.cpan.org
RT-Send-Cc:
Attached is a patch to resolve the problem in Class::Std with shift(@_) not being able to be used in CUMULATIVE methods. It copies the outer-most @_ into an array, and passes that array into all the dispatched-to methods.

Message body is not shown because sender requested not to inline it.

This also patches a much smaller bug later on in the code. There is a part where the array contents are joined together into a string for overloading. If one of the elements is undefined, it will return a warning -- so the one-line change filters out undefined elements.
On Mon Aug 01 17:01:02 2005, dan.kubb@autopilotmarketing.com wrote: Show quoted text
> Attached is a patch to resolve the problem in Class::Std > with shift(@_) not being able to be used in CUMULATIVE > methods. > > It copies the outer-most @_ into an array, and passes that > array into all the dispatched-to methods.
Could you submit an updated patch inclduing tests as per 0.0.9's: http://search.cpan.org/~dmuey/Class-Std- 0.0.9/lib/Class/Std.pm#I_know_we're_all_busy,_I'd_like_to_help_maintain_Class::Std! thanks!