7
|
3
|
50
|
66
|
3
|
0
|
19
|
package OptArgs2::CmdBase;require Scalar::Util;our$_HAS;sub OptArgs2::CmdBase_CI::import {shift;$_HAS={@_ > 1 ? @_ : %{$_[0]}};$_HAS=$_HAS->{'has'}if exists$_HAS->{'has'}}sub __RO {my (undef,undef,undef,$sub)=caller(1);Carp::croak("attribute $sub is read-only")}sub __CHECK {if (my@missing=grep {not exists $_[0]->{$_}}'comment'){Carp::croak('OptArgs2::CmdBase attribute(s) required: ' .join(', ',@missing))}no strict 'refs';my$_attrs=*{ref($_[0]).'::_ATTRS'};map {delete$_attrs->{$_}}keys %$_HAS;Scalar::Util::weaken($_[0]{'parent'})if exists $_[0]{'parent'}&& defined $_[0]{'parent'}}sub _args {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'_args'}//= $_HAS->{'_args'}->{'default'}->($_[0])}sub _opts {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'_opts'}//= $_HAS->{'_opts'}->{'default'}->($_[0])}sub _subcmds {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'_subcmds'}//= $_HAS->{'_subcmds'}->{'default'}->($_[0])}sub _values {if (@_ > 1){$_[0]{'_values'}=$_[1];return $_[0]}$_[0]{'_values'}}sub abbrev {if (@_ > 1){$_[0]{'abbrev'}=$_[1];return $_[0]}$_[0]{'abbrev'}}sub args {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'args'}//= $_HAS->{'args'}->{'default'}->($_[0])}sub comment {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'comment'}}sub hidden {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'hidden'}}sub no_help {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'no_help'}//= $_HAS->{'no_help'}->{'default'}}sub optargs {if (@_ > 1){$_[0]{'optargs'}=$_[1];return $_[0]}elsif (!exists $_[0]{'optargs'}){$_[0]->optargs($_HAS->{'optargs'}->{'default'}->($_[0]))}$_[0]{'optargs'}//= $_HAS->{'optargs'}->{'default'}->($_[0])}sub opts {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'opts'}//= $_HAS->{'opts'}->{'default'}->($_[0])}sub parent {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'parent'}}sub show_color {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'show_color'}//= $_HAS->{'show_color'}->{'default'}->($_[0])}sub show_default {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'show_default'}//= $_HAS->{'show_default'}->{'default'}}sub subcmds {$_[0]->__RO($_[1])if @_ > 1;$_[0]{'subcmds'}//= $_HAS->{'subcmds'}->{'default'}->($_[0])}BEGIN {$INC{'OptArgs2/CmdBase.pm'}=__FILE__} |