/[cvs]/nfo/perl/libs/Getopt/Simple.pm
ViewVC logotype

Contents of /nfo/perl/libs/Getopt/Simple.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Dec 23 04:27:03 2002 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.1: +34 -20 lines
+ refactored, more oo-style now

1 ## ------------------------------------------------------------------------
2 ## $Id: Simple.pm,v 1.1 2002/12/22 14:16:23 joko Exp $
3 ## ------------------------------------------------------------------------
4 ## $Log: Simple.pm,v $
5 ## Revision 1.1 2002/12/22 14:16:23 joko
6 ## + initial check-in
7 ##
8 ## ------------------------------------------------------------------------
9
10
11 package Getopt::Simple;
12
13 use strict;
14 use warnings;
15
16
17 use Data::Dumper;
18 use Getopt::Long;
19
20 my $opt;
21
22 sub _cb_readOption {
23 #my $self = shift;
24 my $opt_name = shift;
25 my $opt_value = shift;
26 $opt_value ||= 1;
27 $opt->{$opt_name} = $opt_value;
28 #$self->{$opt_name} = $opt_value;
29 }
30
31 sub new {
32 my $invocant = shift;
33 my $class = ref($invocant) || $invocant;
34 my $self = {};
35 bless $self, $class;
36
37 #my $fields = shift;
38 my @fields = @_;
39
40 # build mapping (hash with argument as key and callback (CODEref) as value)
41 $self->{__possible} = [];
42 $self->{__available} = [];
43 $self->{__result} = {};
44 $self->{__getopt_mapping} = [];
45 #foreach (@$fields) {
46 foreach (@fields) {
47
48 my $key = $_;
49 $key =~ s/=.*$//;
50 push @{$self->{__possible}}, $key;
51
52
53 #$option_mapping->{$_} = \&readOption;
54 push @{$self->{__getopt_mapping}}, $_;
55 push @{$self->{__getopt_mapping}}, \&_cb_readOption;
56 }
57
58 GetOptions(@{$self->{__getopt_mapping}});
59
60 foreach my $key (keys %{$opt}) {
61 push @{$self->{__available}}, $key;
62 $self->{__result}->{$key} = $opt->{$key};
63 # for convenience: store inside object itself, too
64 $self->{$key} = $opt->{$key};
65 }
66 return $self;
67 }
68
69 sub getOptions {
70 my $self = shift;
71 return $self->{__result};
72 }
73
74 1;

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed