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. |