It would be easier to make auto- or self-loading if you could make a class called Screens, then create a method called main, a method called foo, etc. Then you could move them down after __DATA__, and could therefore use the SelfLoader or AutoLoader. See perlman:perltoot for how to do this.
Once you'd changed to OO syntax, your way of calling this functionality could be:
my $screen_maker = ScreenMaker->new(); $screen_maker->$current_screen();
For backwards compatibility, your &screens function could write stub routines to access the screens, like so:
use ScreenMaker; use Carp qw(carp); sub screens { carp "Using deprecated '&screens' function"; my $screen_maker = ScreenMaker->new(); %screens = ( main => sub { $screen_maker->main() }, foo -> sub { $screen_maker->foo() }, }; }
That way, currently-running code will still work, but will generate warnings that allow you to transform to OO methods.
stephen
In reply to Re: selfloader and anonymous subroutines
by stephen
in thread selfloader and anonymous subroutines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |