Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: New Module Announcement: Object::InsideOut

by diotalevi (Canon)
on Nov 03, 2005 at 16:18 UTC ( #505416=note: print w/ replies, xml ) Need Help??


in reply to New Module Announcement: Object::InsideOut

Did you cover this test case? That ${} dereferencing (or actually, anything) is still legal? That numfication still worked correctly?

use Test::More tests => 2; my $obj = Foo::Bar->new; is( $obj->some_method, "ok" ); is( 0 + $obj, 42 ); package Foo::Bar; use overload '${}' => 'some_method' '0+' => 'numify'; use Object::InsideOut; sub numify { 42 } sub some_method { "ok" }


Comment on Re: New Module Announcement: Object::InsideOut
Download Code
Re^2: New Module Announcement: Object::InsideOut
by jdhedden (Deacon) on Nov 03, 2005 at 21:24 UTC
    Because the object ID is stored in the object's scalar ref (i.e., $$self), overloading ${} deferencing is not allowed. I document this fact in the POD.

    However, all other forms of object deferencing through overloading are supported: Stringify, numerify, boolify, arrayify, hashify, globify and codify. Object::InsideOut simplifies defining these operations through the use of subroutine attributes. For example, your code would become:

    use Test::More 'no_plan'; package Foo::Bar; { use Object::InsideOut; sub numify :Numerify { 42 } } package main; my $obj = Foo::Bar->new(); is(0 + $obj, 42);

    Remember: There's always one more bug.
      If you treat the scalar as an opaque object, store nothing inside it and use overload::StrVal as the key instead, you can allow ${} to be overloaded as well. Data::Postponed uses blessed scalars as the object and allows anything what so ever to be overloaded.
        Then you are back to the same performance problems encountered with Class::Std, namely you have to calculate the object ID on every access.

        It is an engineering trade-off that I feel is more than justified. By storing the object ID in the object's scalar, the only thing you give up is the capability to overload the ${} operator.


        Remember: There's always one more bug.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://505416]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-07-28 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls