User Tools

Site Tools


kurs:extend_getopt--long

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

kurs:extend_getopt--long [2014/09/10 21:22] (current)
Line 1: Line 1:
 +<​code>​
 +package ITAGetopt;
 +
 +use strict;
 +use warnings;
 +use Moose;
 +
 +has '​cl'​ => (is => '​rw',​ isa => '​Str'​);​
 +
 +extends '​Getopt::​Long';​
 +
 +sub new {
 +      my $class = shift;
 +      my $obj = $class->​Getopt::​Long::​Parser::​new(@_);​
 +      return $class->​meta->​new_object(
 +          __INSTANCE__ => $obj, @_,
 +      );
 +}
 +
 +#sub GetOptions {
 +#   my ($self) = shift;
 +#   ​$self->​SUPER::​GetOptions(@_);​
 +#   ...
 +#  ​
 +# won't do it that way, not because it is diffcult but after is easier
 +
 +before '​GetOptions'​ => sub {
 +   print "here I am before ...\n";​
 +   print "@ARGV \n";
 +};
 +
 +
 +after '​GetOptions'​ => sub {
 +   my $self = shift;
 +   print "here I am after ...\n";​
 +   print "@ARGV \n";
 +   ​$self->​cl($ARGV[0]);​
 +};
 +
 +1;
 +</​code>​
 +
 +<​code>​
 +## gopt.pl
 +use strict;
 +use warnings;
 +
 +use ITAGetopt;
 +use Data::​Dumper;​
 +
 +# $opt{opt} = $ARGV[0] if (! $opt{opt} && $ARGV[0]);
 +
 +# $opt{command_line} = $ARGV[0] if $ARGV[0];
 +
 +#my $opt = ITAGetopt::​ITAGetOption(
 +#   '​o|opt:​s'​ => '​opt',​
 +#   '​b|bsp=i'​ => '​bsp',​
 +#);
 +
 +my %opt;
 +my $getopt = ITAGetopt->​new();​
 +my $ref = $getopt->​GetOptions(
 +   '​o|opt:​s'​ => \$opt{opt},
 +   '​b|bsp=i'​ => \$opt{bsp},
 +);
 +
 +printf "​command line %s\n", $getopt->​cl;​
 +</​code>​
 +
 +
  
kurs/extend_getopt--long.txt ยท Last modified: 2014/09/10 21:22 (external edit)