Thread

Posted on Thu Feb 2 23:41:16 2006 by earl
When are Getters defined?

I'm curious; I want to understand when the Getter is defined. I'm using Object::InsideOut v1.33.

This is Foo.pm.
package Foo; use Object::InsideOut; my %goo :Field('Get' => 'get_goo'); warn(defined(&Foo::get_goo) ? 'yes' : 'no'); 1;

I define a subroutine called Foo::get_goo and I check to make sure it is defined.

And this is the main script

#!/usr/bin/perl -w use Foo; warn(defined(&Foo::get_goo) ? 'yes' : 'no'); print "hello.\n";

Here, I check again to make sure Foo::get_goo is defined. When I run this script I get ...

perl test17.pl no at Foo.pm line 6. yes at test17.pl line 4. hello.
Why isn't Foo::get_goo defined within the Foo package? Earl
Direct Responses: 1752 | Write a response
Posted on Fri Feb 3 17:00:53 2006 by jdhedden in response to 1748
Re: When are Getters defined?
The sequence is:
1. During the BEGIN phase, Foo.pm is loaded and its warning statement is executed.
2. During the CHECK phase, accessors are generated.
3. During the 'run' phase, the warning statement in 'main' is executed.

Accessors are also generated, if needed, the first time a 'new' call is made. This handles the cases when fields are dynamically generated using 'create_field', when loading is delayed via 'require', and when used under 'mod_perl'.

See 'perldoc perlmod' for info on the various phases.
Write a response