Image-DS9
view release on metacpan or search on metacpan
lib/Image/DS9/Command.pm view on Meta::CPAN
package Image::DS9::Command;
# ABSTRACT: Command definitions
use v5.10;
use strict;
use warnings;
our $VERSION = 'v1.0.1';
our @CARP_NOT = qw( Image::DS9 );
use Image::DS9::PConsts;
use Image::DS9::Grammar 'grammar';
use Image::DS9::Parser;
use Image::DS9::Constants::V1 'SPECIAL_ATTRIBUTES';
use Ref::Util 'is_arrayref', 'is_scalarref';
use Scalar::Util 'reftype';
use namespace::clean;
sub _croak {
require Carp;
my $fmt = shift;
@_ = sprintf( $fmt, @_ );
goto \&Carp::croak;
}
sub _carp {
require Carp;
my $fmt = shift;
@_ = sprintf( $fmt, @_ );
goto \&Carp::carp;
}
sub new {
my $class = shift;
$class = ref $class || $class;
my $command = shift;
my $opts = shift || {};
my $spec = grammar( $command ) // return;
my $self = bless {
command => $command,
spec => $spec,
opts => $opts,
cvt => 1,
chomp => 1,
retref => 0,
attrs => {},
special_attrs => {},
}, $class;
$self->parse( @_ );
$self;
}
sub parse {
my $self = shift;
my $match = Image::DS9::Parser::parse_spec( $self->{command}, $self->{spec}, @_ );
$self->{$_} = $match->{$_} for keys %$match;
$self->{found_attrs} = exists $self->{attrs};
$self->{name} = $self->{argl}{name} || q{};
$self->{chomp} = $self->{argl}{chomp} if exists $self->{argl}{chomp};
$self->{cvt} = $self->{argl}{cvt} if exists $self->{argl}{cvt};
$self->{retref} = $self->{argl}{retref} if exists $self->{argl}{retref};
# the 'new' and 'now' attributes are special. this needs to be generalized
for my $special ( SPECIAL_ATTRIBUTES ) {
$self->{special_attrs}{$special} = $self->{attrs}{$special} || 0;
( run in 0.574 second using v1.01-cache-2.11-cpan-39bf76dae61 )