http://qs321.pair.com?node_id=742166

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

I have the following class :
package Link; sub FETCH { my $this = shift; return $this->{"site"}; } sub STORE { my ($self,$site) = @_; $self->{"site"} = $site; } sub print_method { my $self = shift; print $self->{"site"}; } sub TIESCALAR { my $class = shift; my $link = shift; my $this = {}; bless($this,$class); $this->{"site"} = $link; return $this; } 1;
and the following code :
use Link; tie my $var,"Link","http://somesite.com"; $var = "http://anothersite.com"; $var->print_method; print $var;
Running the code above results in a runtime error : Can't call method "print_method" without a package or object reference at tietest.pl line 4. . I think I understand why : when fetched , the method returns a string , which doesn't respond to "print_method" . I would like to be able to do the following things : if fetched , print the site's address , if stored , change the address . I would also like to be able to call methods on the object . I am aware that if I return $self from fetch , I will accomplish the "call methods objective" , but that will invalidate the first objective ( fetch ) . Is there a way I could accomplish all of them ?