in reply to Advice please on variable naming style in modules
Your variable naming is quite strange. $self should be the object whose method you are writing, not some parameter. That is within the App package it's the application, within App::Widget it's the widget and within App::Widget::Menu it's the menu. And you, generally, should not access the insides of the App from within an App::Widget::Menu method.
If I understand things right, you pass an app to widget constructor and both app and widget to menu. so the code should be
package App; sub new { my ($class, %args) = @_; my $self = bless { %args }, $class; $self->{widget} = App::Widget->new( $self ); return $self; } package App::Widget; my( $class, $app ) = @_; my $self = bless { }, $class; $app->{menu} = App::Widget::Menu->new( $app, $self); return $self; } package App::Widget::Menu; sub new { my( $class, $app, $widget ) = @_; my $self = bless { }, $class; $app->{some_arg} = 1; $app->{menu}->BackgroundColor(222,222,222); return $self; }
Jenda
Enoch was right!
Enjoy the last years of Rome.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Advice please on variable naming style in modules
by isync (Hermit) on Aug 22, 2012 at 14:42 UTC | |
by Jenda (Abbot) on Aug 22, 2012 at 14:51 UTC | |
by isync (Hermit) on Aug 22, 2012 at 21:08 UTC |
In Section
Seekers of Perl Wisdom