CLI-Gwrap
view release on metacpan or search on metacpan
lib/CLI/Gwrap.pm view on Meta::CPAN
#===============================================================================
#
# PODNAME: CLI::Gwrap.pm
# ABSTRACT: GUI wrapper for command line scripts and programs
#
# AUTHOR: Reid Augustin (REID), <reid@lucidport.com>
# EMAIL: reid@LucidPort.com
# CREATED: 07/06/2013 07:38:28 PM
#===============================================================================
use 5.008;
use strict;
use warnings;
package CLI::Gwrap;
use Moo;
use Types::Standard qw( Str Int Bool ArrayRef CodeRef InstanceOf );
use Carp;
our $VERSION = '0.030'; # VERSION
use CLI::Gwrap::Opt;
use Exporter 'import';
# export the widget builder functions
our @EXPORT_OK = qw(
check
radio
string
hash
integer
float
incremental
label
);
has 'command' => (is => 'ro', trigger => sub {
my ($self, $new) = @_;
$self->{command} = _normalize_name($new);
} );
has 'main_opt' => (is => 'ro', isa => InstanceOf['CLI::Gwrap::Opt']);
has 'description' => (is => 'ro', isa => Str);
has 'gwrapper_name' => (is => 'ro', isa => Str, default => 'wxGrid');
has 'gwrapper' => (is => 'rw');
has 'columns' => (is => 'rw', isa => Int, default => 3);
has 'verbatim' => (is => 'ro', isa => Bool);
has 'help' => (is => 'ro', isa => Str);
has 'persist' => (is => 'ro', isa => Bool);
has 'opts' => (is => 'ro', isa => ArrayRef[InstanceOf['CLI::Gwrap::Opt']]);
has 'advanced' => (is => 'ro', isa => ArrayRef[InstanceOf['CLI::Gwrap::Opt']]);
has 'exec_callback' => (is => 'ro', isa => CodeRef);
has 'timeout' => (is => 'ro', isa => Int);
sub BUILD {
my ($self, $params) = @_;
croak "No command to Gwrap!\n" if(not $self->command);
my $plugin = "CLI/Gwrapper/$self->{gwrapper_name}.pm";
require $plugin;
$plugin = "CLI::Gwrapper::$self->{gwrapper_name}";
my %opts = (
title => $self->command->[0],
);
for my $opt ( qw(
command
main_opt
description
verbatim
help
persist
columns
opts
advanced
exec_callback
timeout
) ) {
$opts{$opt} = $self->$opt if (defined $self->$opt);
}
$self->gwrapper( $plugin->new(%opts) );
if (not $self->gwrapper->DOES('CLI::Gwrapper')) {
die "$plugin doesn't fullfil the CLI::Gwrapper role\n"
}
}
sub title {
my ($self, $new) = @_;
if (@_ > 1) {
$self->gwrapper->title($new);
}
return $self->gwrapper->title;
}
sub run {
my ($self) = @_;
$self->gwrapper->run;
}
#
# Functions (not methods!) to create specific CLI program option types
#
BEGIN {
# convert NAME into [ 'name', 'alias' ] form for simplicity
sub _normalize_name {
my ($name) = @_;
( run in 1.128 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )