Object IO (Typedef problem)

Michael P plumpy at krimedawg.org
Mon Jul 22 19:13:02 CDT 2002

On Mon, 22 Jul 2002, Jason Annin-White wrote:

> I am still pretty much in the same boat however.  I can't find any perl
> documentation on how to typedef a reference to a custom object.

You 'bless' it.  'perldoc -f bless'.  But, see below.

> ref($objectref) returns main.
> ref($$objectref) returns PDX::service

I mean this, of course, in the least condescending way possible: I think
you're doing it wrong.  The reference you get back from Storable should
already be blessed into the package it was originally in.  You shouldn't
have to do anything special to it.

See the sample code below.

> This makes me think that THIS is the appropriate way to access this object:
> PDX::service$$objref->method()

$$objectref->method() might work.  It's hard to say, though, depending on
what other magic you're doing elsewhere.

Here's some extremely pared-down code that might help you with basic
Storable usage:


use strict;
use Storable;

my $created = PDXPM->new();
# Save this newly created object in the file "pdxpm.store".
store($created, "pdxpm.store");

# Retrieve the data out of the file.
my $loaded = retrieve("pdxpm.store");

# Object definitions...
package PDXPM;

sub new {
  my $proto = shift;
  return bless({}, ref($proto) || $proto);

sub set_name {
  my $self = shift;
  $self->{_name} = shift;

sub get_name {
  my $self = shift;
  return $self->{_name};

sub hello {
  my $self = shift;
  print "Hello, ", $self->get_name(), "!\n";


More information about the Pdx-pm-list mailing list