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

Thank you! I have no idea why I didn't think about it before... Now it does seem like an obvious solution. I still didn't get it to work though. I did exactly what you suggested, but now I get this error: (I'm using Storable for serializing data in MLDBM) Can't store CODE items at blib\lib\Storable.pm (autosplit into blib\lib\auto\Storable\_freeze.al) line 264, at C:/Perl/site/lib/MLDBM/Serializer/Storable.pm line 20
  • Comment on Re: Re: Need a workaround: Class variables with MLDBM::Sync

Replies are listed 'Best First'.
Re: Re: Re: Need a workaround: Class variables with MLDBM::Sync
by perrin (Chancellor) on Oct 11, 2002 at 21:09 UTC
    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.

      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.

Re^3: Need a workaround: Class variables with MLDBM::Sync
by diotalevi (Canon) on Oct 12, 2002 at 01:42 UTC

    Perhaps you're running into the same issue that was being addressed over here. (or related anyway). The jist is you should see about upgrading your Storable and maybe perl itself.

    __SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B:: +svref_2object(sub{})->OUTSIDE