in reply to Re: Re: Need a workaround: Class variables with MLDBM::Sync
in thread Need a workaround: Class variables with MLDBM::Sync

I can't tell you what's going on without seeing your code. Make sure you are only tie-ing the data, not the whole calendar object.
  • Comment on Re: Re: Re: Need a workaround: Class variables with MLDBM::Sync

Replies are listed 'Best First'.
Re: Re: Re: Re: Need a workaround: Class variables with MLDBM::Sync
by relax99 (Monk) on Oct 14, 2002 at 15:58 UTC

    What happens is Storable can not convert Perl code, which is what this MLDBM::Sync lock object is, into something it can store on disk. I haven't resolved the issue yet. I'm trying to use Data::Dumper, since it can work with Perl code, or, more precisely, it stores objects by converting them to Perl code.

      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.