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

Hi monks,
I am wondering when the default methods ( *_isset, *_reset) of Class::MathodMaker gets created. Whether it gets created at the time of instantiation or only when it is invoked ($obj->field_reset). Would some one help me in debugging or inspecting the methods that get created from an MethodMaker object. Here is my sample code

package class; use Data::Dumper; use Class::MethodMaker get_set => [ qw/ field_1 field_2 field_3 field_4 field_5 +/] , new_with_init => 'new', new_hash_init => 'hash_init' ; sub init { my $self = shift ; $self->hash_init(@_) ; } my %values = map { 'field_'.$_ => $_ } (1 .. 5 ); my $class = class->new(\%values); print Dumper($class); 1;
In Dumper result I am just getting the fields. I want to know all the possible methods that can be called from $class( including the deafults *_reset, *_isset ...). Please help me with more inspection or debugging modules to inspect the $class object.
Thanks,
Siraj



Thanks for the help, it helped me a great, also I found another module Class::Inspector to inspect the methods in the object.

print Dumper(Class::Inspector->methods($class);

Replies are listed 'Best First'.
Re: when is *_reset methods of Class::MethodMaker gets created
by almut (Canon) on May 14, 2008 at 11:54 UTC

    You could dump the package's symbol table at various places, for example before and after using Class:MethodMaker:

    package class; use Data::Dumper; BEGIN { $Data::Dumper::Sortkeys = 1; print 'Before "use Class::MethodMaker": '; print Dumper(\%{*class::}); } use Class::MethodMaker get_set => [ qw/ field_1 field_2 field_3 field_4 field_5 +/] , new_with_init => 'new', new_hash_init => 'hash_init' ; BEGIN { print 'After "use Class::MethodMaker": '; print Dumper(\%{*class::}); } # ...

    The output

    Before "use Class::MethodMaker": $VAR1 = { 'BEGIN' => *class::BEGIN, 'Dumper' => *class::Dumper }; After "use Class::MethodMaker": $VAR1 = { 'BEGIN' => *class::BEGIN, 'Dumper' => *class::Dumper, 'clear_field_1' => *class::clear_field_1, 'clear_field_2' => *class::clear_field_2, 'clear_field_3' => *class::clear_field_3, 'clear_field_4' => *class::clear_field_4, 'clear_field_5' => *class::clear_field_5, 'field_1' => *class::field_1, 'field_1_isset' => *class::field_1_isset, 'field_1_reset' => *class::field_1_reset, 'field_2' => *class::field_2, 'field_2_isset' => *class::field_2_isset, 'field_2_reset' => *class::field_2_reset, 'field_3' => *class::field_3, 'field_3_isset' => *class::field_3_isset, 'field_3_reset' => *class::field_3_reset, 'field_4' => *class::field_4, 'field_4_isset' => *class::field_4_isset, 'field_4_reset' => *class::field_4_reset, 'field_5' => *class::field_5, 'field_5_isset' => *class::field_5_isset, 'field_5_reset' => *class::field_5_reset, 'get_field_1' => *class::get_field_1, 'get_field_2' => *class::get_field_2, 'get_field_3' => *class::get_field_3, 'get_field_4' => *class::get_field_4, 'get_field_5' => *class::get_field_5, 'hash_init' => *class::hash_init, 'isa' => *class::isa, 'new' => *class::new, 'set_field_1' => *class::set_field_1, 'set_field_2' => *class::set_field_2, 'set_field_3' => *class::set_field_3, 'set_field_4' => *class::set_field_4, 'set_field_5' => *class::set_field_5 };

    suggests that the methods are being set up at use time of the module Class::MethodMaker.