Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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.

Replies are listed 'Best First'.
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?
[Corion]: ... in Pg, but that would mean that I'd have to deal with credentials and stuff :)
[Corion]: In fact, the whole thing is just four simple programs, one App::scrape, another being DBIx::RunSQL, and one some glue to convert a JSON object into an SQL INSERT statement (+DBI connect/execute), so it would be an incredibly simple solution...
[Corion]: ... but that simplicity falls down due to SQLite letting me down and me being too lazy to move to a real DB. Maybe DBD::CSV can handle window functions...
[hippo]: Pg has the "trust" mechanism if you don't fancy using credentials for a trivial db.
[Corion]: hippo: Oooh, that sounds quite nice - let me read the documentation on that :)
[hippo]: https://www. postgresql.org/ docs/current/ static/auth- methods.html#AUTH- TRUST
[erix]: or compile & run an instance as yourself (not user 'postgres')
[erix]: easiest setup is to run with PG* env variables set, and a custom .pgpass files (can be a $PGPASSFILE)
[Corion]: Hmm - "trust" sounds interesting, but I have still to find whether I can restrict that on a per-DB level ;)
[Corion]: erix: Sure, but SQLite doesn't even need that :)

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2018-02-23 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (302 votes). Check out past polls.

    Notices?