Contenu connexe
Similaire à Advanced modulinos trial (20)
Advanced modulinos trial
- 1. Advanced
Modulinos
★ brian d foy
The Perl Review
Houston Perl Mongers
- 17. % perl hello.pl
Hello World!
% perl hello.pl Houston
Hello World!
% perl hello.pl -m Texas
Hello World!
% perl hello.pl < partiers
Hello World!
- 18. Connect the
command line to new()
% hello.pl -s Houston
?
use Hello;
new()
my $app->new(
input => $in_fh,
output => $out_fh,
message => $message,
);
$app->greet;
- 19. sub run {
my( $class, @args ) = @_;
my %args =
$class->process_args(@args);
my $self = $class->new(%args);
say { $self->fh }
$self->message;
}
- 20. sub process_args {
require Getopt::Std;
local @ARGV = @_;
getopts('oim:', my %opts);
$opts('o') //= *STDOUT;
$opts('i') //= *STDIN;
$opts('m') //= 'Hello World!';
# left over @_?
my %args = map {
$opts_map{$_} => $opts{$_}
} keys %opts;
}
- 22. sub new {
my( $class, %args ) = @_;
my $self = bless {}, $class;
foreach ( keys %args ) {
# maybe more complicated
$self->set( $_, $args{$_} );
}
return $self;
}