fuzzyping has asked for the wisdom of the Perl Monks concerning the following question:
------------------------------------------------------------package Menu; use strict; use Data::Dumper; sub new { my ($self, %args) = @_; bless { _title => $args{title} || die "Sorry, we need a title for this + menu!", _header => $args{header}, _comment => $args{comment} }, $self; } sub set_choices { my ($self, %choices) = @_; my $count; foreach (keys %choices) { $self->{$_} = ( _id => $_, _name => $choices{$_}{name} || die "Sorry, we need a name +for this menu entry!", _sub_or_id => $choices{$_}{sub_or_id} || 0, _return_sub => $choices{$_}{return_sub} ); } } sub print { my $self = shift; print Dumper $self; } 1;
------------------------------------------------------------#!/usr/bin/perl # test_menu.pl use strict; use lib qw(.); use Menu; my $menu = Menu->new( title => "Testing menu", header => "Just testing...", comment => "Ok, this is where the comment section would normal +ly go." ); my %entries = ( 1 => { name => "Entry #1" }, 2 => { name => "Entry #2" }, 3 => { name => "Entry #3" }, 4 => { name => "Quit" } ); $menu->set_choices(%entries); $menu->print;
[jason@lappy jason]$ perl test_menu.pl $VAR1 = bless( { '1' => 'Entry #1', '2' => 'Entry #2', '3' => 'Entry #3', '4' => 'Quit', '_title' => 'Testing menu' }, 'Menu' );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Designing a package object
by PhiRatE (Monk) on Jul 25, 2002 at 05:47 UTC | |
|
Re: Designing a package object
by dpuu (Chaplain) on Jul 25, 2002 at 04:04 UTC | |
by fuzzyping (Chaplain) on Jul 25, 2002 at 04:12 UTC | |
|
Re: Designing a package object
by djantzen (Priest) on Jul 25, 2002 at 05:01 UTC |