Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
See Class::Tables for the full code. The basic idea is that the object implementation is a blessed scalar holding the tuple's primary key. I can also tell what database table it belongs to by what class it's blessed into. I use these two pieces of information to address a deep hash with all the accessor data. The general idea is:
my $DATA; sub id { ${+shift} } # $obj->column_name() # $obj->field("column_name") sub field { my ($self, $col) = @_; my $table = (ref $self)->_table; my $id = $self->id; return $DATA{$table}{$id}{$col}; }
The DESTROY method I gave in the previous post was for the benefit of theAcolyte and the basic inside-out mechanism. You're right that in my code, since the data should stay around as long as there's an object that might need it, I have to do something a little more clever. I end up doing my own form of reference counting. Each time I make an object, I increment $COUNT{$table}{$id}. Each time an object is destroyed, I decrement that count and if the count became zero, clear out the appropriate part of the %DATA hash (and %COUNT as well).

blokhead


In reply to Re^3: Why is a hash the default "object" in oo perl? by blokhead
in thread Why is a hash the default "object" in oo perl? by theAcolyte

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found