summaryrefslogtreecommitdiff
path: root/lib/Getopt/Dakkar/Role/Piece.pm
blob: 144f9e78cf4ad72a8a4bd6f663db67fd31455965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package Getopt::Dakkar::Role::Piece; 
use Getopt::Dakkar::Style qw(role);
# VERSION 
# ABSTRACT: a piece 
 
has name => ( is => 'ro'isa => Str, required => 1 );
has class => ( is => 'ro'isa => ClassName, default => 'Getopt::Dakkar::Stash' );
has object => ( is => 'ro'isa => Object );
has op => ( is => 'ro'isa => Str|CodeRef );
 
sub make_stash($self,$argpack) {
    if (my $o = $self->object) { return $o }
 
    my $class = use_module($self->class);
    if (my $from_argpack = $class->can('new_from_argpack')) {
        return $class->$from_argpack($argpack);
    }
    else {
        return $class->new();
    }
}
 
requires 'parse';