Skip Menu |

This queue is for tickets about the Hook-LexWrap CPAN distribution.

Report information
The Basics
Id: 68251
Status: open
Priority: 0/
Queue: Hook-LexWrap

People
Owner: Nobody in particular
Requestors: rledousa [...] yahoo.com
Cc:
AdminCc:

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



Subject: can't modify @_ when using pre wrapper
Hi- In reading the docs on cpan, it appears that I can alter @_ of the wrapped sub in a pre wrapper. If I try to change an arg directly, I get a "can't modify constant item" error: sub pre { $_[1] = 'foo'; } sub t { print Dumper(\@); } wrap *t, pre => \%pre; If use splice, similar to the the example in the docs: sub pre { @_ = ($_[0], 'foo', splice @_, 1); } I don't get an error, but the arg list is not modified. Is this a bug or am I misunderstanding the docs? thanks ahead of time!
On Mon May 16 18:55:07 2011, rledousa wrote: Show quoted text
> In reading the docs on cpan, it appears that I can alter @_ of the > wrapped sub in a pre wrapper. > > If I try to change an arg directly, I get a "can't modify constant item" > error:
You didn't provide full example. For example, this code works correctly: use Hook::LexWrap; use Data::Dumper; sub pre { $_[1] = 'foo'; } sub t { print Dumper(\@_); } wrap *t, pre => \⪯ @args = (4,5,6); t(@args); If you call t with constant second argument, it means that second argument is an alias to a constant, so you can't modify it. -- Alexandr Ciornii, http://chorny.net
Subject: Re: [rt.cpan.org #68251] can't modify @_ when using pre wrapper
Date: Mon, 16 May 2011 16:42:02 -0700 (PDT)
To: "bug-Hook-LexWrap [...] rt.cpan.org" <bug-Hook-LexWrap [...] rt.cpan.org>
From: Roy Ledochowski <rledousa [...] yahoo.com>
Hi- Thanks for the quick reply.  I didn't give you a full example because my test is contained in a couple of classes  and it seemed to long to include, but here it is: ######## Foo/Y.pm package Foo::Y; require v5.8.0; use strict; use diagnostics; use Data::Dumper; use lib qw(/home/rledo/perllib); require Exporter; our $VERSION = 1.00; our @ISA = qw(Exporter); # symbols to export by request our @EXPORT_OK = qw(pre); # symbols to export by default our @EXPORT = qw(); our %EXPORT_TAGS = ( ); sub pre {     print "******\n";     print "pre\n";     print Dumper(\@_);         # wrapped sub won't run if $_[-1] is assigned     #$_[-1] = 'assigned';         @_ = ($_[0], 'em', splice @_, 1);     } 1; ############ Foo/X.pm (this has the wrappers): package Foo::X; require v5.8.0; use lib qw(/home/rledo/perllib); #use parent qw(Foo::Y); use Foo::Y qw(pre); use strict; use diagnostics; use Data::Dumper; use Hook::LexWrap; our $pvar = 'hello world'; my $lvar = 'goodbye cruel world'; sub t(); wrap *t, pre => \&pre; sub new {     my ($this, $args) = @_;     my $class = ref($this) || $this;     my $self = {         dbh => 'handle'     };     bless $self, $class;     return $self; } sub t { #    my $self = shift;     print "t(): hello world\n";     print Dumper(\@_);     return; } 1; ######## and the test script: use strict; use diagnostics; use Data::Dumper; use lib qw(/home/rledo/perllib); use Foo::X; my $x = Foo::X->new(); $x->t(); $x->t('arg1', 'arg2');          <-- I expect to see 'em' from the wrapper method prepended to these Show quoted text
________________________________ From: Alexandr Ciornii via RT <bug-Hook-LexWrap@rt.cpan.org> To: rledousa@yahoo.com Sent: Monday, May 16, 2011 4:02 PM Subject: [rt.cpan.org #68251] can't modify @_ when using pre wrapper <URL: https://rt.cpan.org/Ticket/Display.html?id=68251 > On Mon May 16 18:55:07 2011, rledousa wrote:
> In reading the docs on cpan, it appears that I can alter @_ of the > wrapped sub in a pre wrapper.  > > If I try to change an arg directly, I get a "can't modify constant item" > error:
You didn't provide full example. For example, this code works correctly: use Hook::LexWrap; use Data::Dumper; sub pre { $_[1] = 'foo'; } sub t { print Dumper(\@_); } wrap *t, pre => \&pre; @args = (4,5,6); t(@args); If you call t with constant second argument, it means that second argument is an alias to a constant, so you can't modify it. -- Alexandr Ciornii, http://chorny.net