You're trying to store the MLDBM::Sync object inside of MLDBM::Sync? Don't do that! Here's the sort of thing I had in mind:
package Calendar; # constructor sub new { my $class = shift; my %args = @_; my $calendar = {}; my %data; my $sync_dbm_obj = tie(%data, 'MLDBM::Sync', "$args{DIR}\\$arg +s{year}.db", O_CREAT|O_RDWR, 0640) or die "can't open tie to $args{year}.db: $!"; $calendar->{'data'} = \%data; # if just created, initialize hash with default values if( !$calendar->{data}{months} ) { $sync_dbm_obj->Lock; $calendar->{data}{year} = $args{year}; $calendar->{data}{months} = {}; my $aref = $calendar->{data}{months}; foreach my $month (1..12) { $aref->{$month} = _init_days($calendar->{data}{year}, $mon +th); } $calendar->{data}{months} = $aref; $sync_dbm_obj->UnLock; } return bless $calendar, $class; }
When you need access to the MLDBM::Sync object you just say my $sync_dbm_obj = tied $calendar->{data} to get it.

Of course this is not an OO approach. If you really want to use OO, you should make accessor methods for $calendar->months(), $calendar->year(), etc. instead of just using a tied hash.


In reply to Re(5): Need a workaround: Class variables with MLDBM::Sync by perrin
in thread Need a workaround: Class variables with MLDBM::Sync by relax99

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.