Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

lvalues in perl prior to 5.16.3 throws "Can't modify reference constructor in lvalue subroutine return"

by hurricup (Pilgrim)
on Jan 22, 2015 at 09:02 UTC ( [id://1114115]=perlquestion: print w/replies, xml ) Need Help??

hurricup has asked for the wisdom of the Perl Monks concerning the following question:

Hi there!

I've decided to create a useful module to generate class properties. I've done it and it works fine on perl 5.16.3+, but older perls don't want to compile it.

Module can be found here.

The main idea is generating lvalue properties using tie and closure:

sub get_property { my( $getter, $setter ) = @_; require Class::Property::RW::Custom; my $dummy; my $wrapper = tie $dummy, 'Class::Property::RW::Custom', $getter, +$setter; return sub: lvalue { $wrapper->set_object(shift); return $dummy; # <= here is error in older perls }; }

Error message is not quite clear and i don't understand, what is wrong. Please, help.

  • Comment on lvalues in perl prior to 5.16.3 throws "Can't modify reference constructor in lvalue subroutine return"
  • Download Code

Replies are listed 'Best First'.
Re: lvalues in perl prior to 5.16.3 throws "Can't modify reference constructor in lvalue subroutine return"
by ikegami (Patriarch) on Jan 22, 2015 at 15:32 UTC

    Works for in all versions I've tried, and I tried as far back as 5.8.8.

    Test:

    perl -MTie::Scalar -le' sub make { return sub :lvalue { tie my $tied, "Tie::StdScalar"; return $tied; } } my $f = make(); $f->() = 4; '

    If you beg to differ, please provide code that demonstrates the problem. What you posted doesn't run.

      Thanks to everyone for answers.

      The problem is that at home i've got only win7 and production FreeBSD with modern perl versions. Perlbrew don't want to work at my win machine.

      Today i've installed few virtualboxes with other oses, will try there on the weekend.

      All fails i know are coming from CPANTESTERS, including os and perl versions.

      I'll let you know about my further investigation of this issue.

      btw, are bugs fixed in 5.16 are still present in prior perl versions?

Re: lvalues in perl prior to 5.16.3 throws "Can't modify reference constructor in lvalue subroutine return"
by choroba (Cardinal) on Jan 22, 2015 at 11:00 UTC
    What is the error message, then?

    Have you studied the deltas?

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: lvalues in perl prior to 5.16.3 throws "Can't modify reference constructor in lvalue subroutine return"
by LanX (Saint) on Jan 22, 2015 at 11:17 UTC
    I guess (?) you are trying to apply the lvalue attribute on an anonymous sub.

    I wouldn't expect this to work, ( well it does in 5.14 see update 2)

    You may try creating a temporary named sub with lvalue and pass the reference, but I'm not sure about implementation details and side effects.

    update 1

    Since when are lvalue subs allowed to use return ?

    update 2

    was able to test now and 5.14 allows anonymous lvalue subs, but return won't work.

    perl -e' $z=10; $x=sub :lvalue { $z}; (&$x)=42; print &$x; ' 42

    maybe try to further isolate the problem...

    Cheers Rolf

    PS: Je suis Charlie!

Re: lvalues in perl prior to 5.16.3 throws "Can't modify reference constructor in lvalue subroutine return"
by LanX (Saint) on Jan 22, 2015 at 11:54 UTC
    > Error message is not quite clear

    $ echo "Can't modify reference constructor in lvalue subroutine return +"|splain Can't modify reference constructor in lvalue subroutine return (#1) (F) You aren't allowed to assign to the item indicated, or otherwi +se try to change it, such as with an auto-increment.

    I suppose your tie is loading too much magic onto $dummy ... but this would be a runtime error not compilation like you indicated(?)

    Please try to give a concise sample reproducing your problem, I'm not motivated to dig into your module to do the binary debugging search for you. ;-)

    ... and please name concrete Perl version numbers failing.

    Cheers Rolf

    PS: Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1114115]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-19 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found