I have a script that ties to Apache::Session and I'm trying to have Apache::Session save the lower level classes, but this doesn't seem to be happening. When I run test with an argument it fills all the objects properly. When I run test without an argument then Apache::Session should restore the values of the objects stored in the last session run. This is not happening, and I can't seem to figure out why. Can anyone see what I'm doing wrong? Is their a better way to do this? Any help or suggestions are appreciated.

Thanks,
Steve
package Item; $VERSION = 1.0; use strict; use Class::MethodMaker new_with_init => 'new', new_hash_init => '_init_args', static_hash => 'counter', get_set => [qw( sku qty )]; sub count { $_[0]->counter('count') } sub _incr_count { $_[0]->counter(count=>$_[0]->counter(' +count')+1) } sub _decr_count { $_[0]->counter(count=>$_[0]->counter('count')- +1) } sub init { my ($self, %args) = @_; $self->_init_args(%args); $self->_incr_count(); return $self; } sub DESTROY { $_[0]->_decr_count(); } package Info; $VERSION = 1.0; use strict; use Apache::Session::MySQL; use Class::MethodMaker "-sugar"; make methods new_with_init => 'new', object_list => [ Items => 'items' ], get_set => [qw( orderid )]; sub timestamp { $_[0]->{_timestamp} = time() } sub cid { $_[0]->{_session_id} } sub init { my ($self, %args) = @_; tie %{ $self }, 'Apache::Session::MySQL', $args{cid}, { DataSource => 'dbi:mysql:ssdw_store', UserName => 'web', Password => 'webpass1', LockDataSource => 'dbi:mysql:ssdw_store', LockUserName => 'web', LockPassword => 'webpass1', }; $self->timestamp; return $self; } sub DESTROY { $_[0]->timestamp; untie %{$_[0]}; } 1;
and the test script. Note: I ran this with an undef cid the first time and then I entered the cid so that I was recalling the same session each time.
#!/usr/bin/perl use lib "."; use Info; use Item; my $id = '3c85ccbef20f62dd495e9b9b958bf040'; my $info = Info->new('cid'=>$id); print "Cid: ", $info->cid, "\n"; if ($ARGV[0]) { $info->clear_items(); $info->push_items(Item->new(sku=>'123123',qty=>1)); $info->push_items(Item->new(sku=>'123321',qty=>2)); } print $info->count_items(), "\n"; while ($x = $info->pop_items) { print "Sku: ", $x->sku, " Qty: ", $x->qty, "\n"; } exit;
Thanks Again.

In reply to Session Persistance Problems by steveAZ98

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.