Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Simple question about Inside-Out objects

by Herkum (Parson)
on Mar 13, 2007 at 17:44 UTC ( #604627=note: print w/ replies, xml ) Need Help??


in reply to Simple question about Inside-Out objects

In a inside-out implementation, you need to a way to identify the object that you are working with. The only difference between different objects of the same class are their addresses. by using refaddr we can uniquely identify our objects and hidden the variables in each object from each other.

A very short example

package Foo::Bar; use Scalar::Util qw(refaddr); my %var; sub get_var { my $self = shift; return $var{ refaddr( $self ) }; } sub set_var { my $self = shift; my $value = shift; $var{ refaddr( $self ) } = $value; return 1; } # Not completely sure that this is correct. sub new { my $class = shift; return bless \my($anon_scalar), $class; }

Take a look at Class::Std or Damian Conway's Best Practices on the concept.


Comment on Re: Simple question about Inside-Out objects
Download Code
Re^2: Simple question about Inside-Out objects
by xdg (Monsignor) on Mar 13, 2007 at 19:25 UTC
    Take a look at Class::Std

    No, please don't. Look at Object::InsideOut or Class::InsideOut instead. For a full review of the technique, see my YAPC::NA 2006 presentation, Eversion 101.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      I have looked at both of them and the reason that I don't use them is the same reason that I don't use a lot of other 'good' modules, poor documentation.

      While I understand that Class::Std is not the perfect for solving all the problems for InsideOut objects. The concepts well explained and the documentation is easier to understand. That is why I recommended it to blazar

        the reason that I don't use them is the same reason that I don't use a lot of other 'good' modules, poor documentation

        I'd welcome any constructive feedback on the documentation of Class::InsideOut. I've tried hard to make that documentation simple for those who just want it to work and keep separate the theoretical underpinnings and complexities. I'm sorry that you didn't find it to be helpful and would like to hear your thoughts on what would make it more useful to you.

        I can be reached via dagolden at cpan dot org.

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-12-19 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (94 votes), past polls