locked_user sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:

The synopsis for MojoX::Session seems to say that undef $session; will cause the flush() method to be called on the object.

Is that true? If so, how in the heck does it work?

Replies are listed 'Best First'.
Re: A question about Mojo's "mojo"
by Fletch (Bishop) on Jan 14, 2009 at 21:36 UTC

    The most immediately obvious mechanism would be that the class' DESTROY does it on the way out.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: A question about Mojo's "mojo"
by shmem (Chancellor) on Jan 14, 2009 at 22:45 UTC

    No, it's not true. It would be done as Fletch says. Seems like it was planned at the synopsis writing time, but hasn't been implemented. But let's see if there's some magic.

    A private copy in my $PERL5LIB directory, patched as follows...

    --- /usr/lib/perl5/site_perl/5.8.8/MojoX/Session.pm +++ /home/shmem/comp/perl/lib/MojoX/Session.pm @@ -81,7 +81,7 @@ sub flush { my $self = shift; - +warn "LAST ORDERS. FASTEN SEAT BELTS...\n"; return unless $self->sid && !$self->_is_flushed; if ($self->is_expired && $self->_is_stored) {

    ... used within this script...

    use MojoX::Session; my $session = MojoX::Session->new; $session->create(); $session->data('foo' => 'bar'); warn $session->data('foo'),$/; undef $session; warn "did we land yet?\n"; my $session = MojoX::Session->new; $session->create(); $session->data('bar' => 'baz'); print $session->data('bar'),$/; $session->flush(); warn "end-of that.\n"

    ... produces...

    bar did we land yet? baz LAST ORDERS. FASTEN SEAT BELTS... end-of that.

    ... which shows that just undefining $session doesn't call flush(). How could it? there's no DESTROY method.