in reply to Destringify class

How are you executing the script that you write? If it's a completely separate process, it can't access the object that created it.

If you're using do or require, you can make $self a kind of global that the script can access.

If you fork and execute the separate process, it has access to everything that was there at the time of the fork. This is a slightly modified case of one of the above, but it's important to note that the object in the child will not be the same as the one that wrote the script. Rather, it will be a copy. It can do the same things, but it can't modify the original.

In answer to the question you asked, have a look at Devel::Pointer.

For a more detailed answer, I think you'll have to show us some code.

Replies are listed 'Best First'.
Re^2: Destringify class
by bgiii (Sexton) on Aug 12, 2008 at 20:34 UTC
    I am using 'require' to execute the script. The only reason I am doing this is that I need the facilities of Filter::cpp, and it has to run on a file, as far as I can tell. If I could run this internally, it'd be a lot easier.

      Here's a demonstration of what I was writing about:

      use strict; use warnings; package My::Self; sub new { bless $_[1] } package main; my $obj = My::Self->new({ authentic => int rand 1_000_000 }); my $to_be_required = './deleteme.pl'; open my $out_fh, '>', $to_be_required or die "Can't write '$to_be_required': $!"; print {$out_fh} <<"END_OF_SUBSCRIPT"; print "My name is '$to_be_required'\n"; print "I've heard of this self: ", \$main::self_everyone_knows->{authentic}, "\n"; print "Have a nice day!\n"; END_OF_SUBSCRIPT ; close $out_fh; $main::self_everyone_knows = $obj; require $to_be_required; print "Did it know $obj->{authentic}?\n"; unlink $to_be_required or die "Can't unlink '$to_be_required': $!"; __END__ My name is './deleteme.pl' I've heard of this self: 507287 Have a nice day! Did it know 507287?

      Some things to note:

      • This tosses out a warning about $main::self_everyone_knows being used only once.
      • I've set $main::self_everyone_knows after I wrote the file. Its value isn't used when writing the file actually. In the file, there's a literal "$main::self_everyone_knows", but the first line will be "print "My name is './deleteme.pl'\n"". $main::self_everyone_knows just has to have its value before the require.
      • You can do whatever you want to the file between when you write it and when you require it.