in reply to Calling an intermediate method
Not quite sure what you mean. Maybe like this?
package Foo { sub new { bless [] }; sub msg { my $self = shift; printf "On my way to '%s'\n", @_; } sub Berlin { my $self = shift; $self->msg('Berlin'); print "I'm in Berlin!\n"; } sub Paris { my $self = shift; $self->msg('Paris'); print "I'm in Paris!\n"; } }; my $obj = Foo->new; $obj->Berlin();
Or maybe you mean like this?
package Foo { sub new { bless [] }; sub msg { my $self = shift; printf "On my way to '%s'\n", @_; } sub Berlin { my $self = shift; print "I'm in Berlin!\n"; } sub Paris { my $self = shift; print "I'm in Paris!\n"; } }; use Class::Method::Modifiers qw( install_modifier ); for my $city (qw/ Paris Berlin /) { install_modifier "Foo", before => $city => sub { my $self = shift; $self->msg($city); }; } my $obj = Foo->new; $obj->Berlin();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calling an intermediate method
by trizen (Hermit) on Dec 19, 2013 at 00:20 UTC | |
by tobyink (Canon) on Dec 19, 2013 at 10:59 UTC |