Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I agree; this seems broken. Small test case...

use strict; use warnings; use Test::More; { package Thing; use Moose; has attr => (is => 'ro'); } { package ThingWithRef; use Moose; has attr => (is => 'ro'); sub translate_to_dutch { my $self = shift; ${ $self->attr } =~ s/e/a/; } } my $obj1 = Thing->new(attr => 'Hello'); my $obj2 = ThingWithRef->new(attr => \$obj1->attr); $obj2->translate_to_dutch; is($obj1->attr, 'Hallo'); done_testing;

If you use Moo instead of Moose, then things work as expected.

UPDATE: OK, not a bug. It's just that the reference \$obj1->attr is not guaranteed to be a reference to the slot within the object. So changing data via the reference will not necessarily effect $obj1. If it works, it works; if not, then it won't; no guarantees. Currently it works in Moo but not Moose, but the situation - in either - could change.

If you want what you want (for both objects to have access to the same piece of data) then you need it to be a scalar ref in both classes.

UPDATE 2: It also fails in Moo if Moo is in pure Perl mode (not XS).

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: Possible issue with Moose ScalarRef by tobyink
in thread Possible issue with Moose ScalarRef by greengaroo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (7)
    As of 2014-07-13 11:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (249 votes), past polls