When you need access to the MLDBM::Sync object you just say my $sync_dbm_obj = tied $calendar->{data} to get it.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; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |