Advertisement
oylenshpeegul

use Moo::Getopt

Nov 28th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.72 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use v5.14;
  4. use warnings;
  5.  
  6. package t {
  7.     use Moo;
  8.     with 'Moo::Getopt';
  9.      
  10.     has 'bool' => (is => 'rw');
  11.     has 'str' => (is => 'rw');
  12.     has 'array' => (
  13.         is => 'rw',
  14.         coerce => sub {
  15.             my ($p) = @_;
  16.             if (defined $p and ref $p ne 'ARRAY') {
  17.                 $p = [split /,/, $p];
  18.             }
  19.             $p;
  20.         }
  21.     );
  22.     has 'z' => (is => 'rw');
  23.  
  24.     sub getopt {
  25.         'USAGE: %c %o',
  26.         ['bool', 'bool test', {required => 1}],
  27.         ['str=s', 'str test'],
  28.         ['array=s', 'array test'],
  29.         ['z=s', 'array params test'],
  30.     }
  31. }
  32.  
  33. my $t = t->new_with_options;
  34.  
  35. say $t->bool;
  36.  
  37. say join q{ }, @{$t->array};
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement