Agent-TCLI
view release on metacpan or search on metacpan
lib/Agent/TCLI/Command.pm view on Meta::CPAN
use warnings;
use strict;
our $VERSION = '0.030.'.sprintf "%04d", (qw($Id: Command.pm 59 2007-04-30 11:24:24Z hacker $))[2];
use Object::InsideOut qw(Agent::TCLI::Base);
use Getopt::Lucid qw(:all);
use FormValidator::Simple;
=head2 ATTRIBUTES
The following attributes are accessible through standard named accessor/mutator
methods unless otherwise noted
=over
=item name
The name of the command. This is the word that is used to call the command.
It should be long enough to be descriptive. Use aliases for shortenned
versions or abbreviations.
The name is also the key used in a Package's commands hash. Thus is must
be unique within a package.
B<set_name> will only accept SCALAR type values.
=cut
my @name :Field :All('name');
=item topic
The general topic heading that the command will be listed under.
Most applicable to help menus.
B<set_topic> will only accept SCALAR type values.
=cut
my @topic :Field :All('topic');
=item help
Brief text to decribe the function of the command. This should be
a one line description.
B<set_help> will only accept SCALAR type values.
=cut
my @help :Field :All('help');
=item usage
Brief illustration of usage. Complex commands may want to show how to call
help / manual instead.
B<set_usage> will only accept SCALAR type values.
=cut
my @usage :Field :All('usage');
=item manual
A long desciption of the command and its use. This text will be followed
by the command's parameter's manul sections if provided.
B<manual> will only contain scalar values.
=cut
my @manual :Field
# :Type('scalar')
:All('manual');
=item command
A reference to the sub routine that will execute the command
or the name of the package session that will run the command.
=cut
my @command :Field :All('command');
=item start
Deprecated: A reference to a subroutine that is necessary to intialize the command at control startup.
B<start> will only accept CODE type values.
=cut
my @start :Field :All('start')
:Type('CODE');
=item stop
Deprecated: A code reference for shutting down anything as the control shuts down.
B<stop> will only accept CODE type values.
=cut
my @stop :Field :All('stop')
:Type('CODE');
=item handler
A code reference for a response handler if necessary for a
POE event driven command
=cut
my @handler :Field :All('handler');
=item call_style
This is a holdover to facilitate migration from the older style method
of calling commands with an oob, to the new POE parameter use. The value
'poe' means the command is called directly with the normal POE KERNEL
HEAP and ARGs. 'session' means that a POE event handler is called.
B<call_style> will only accept SCALAR type values.
=cut
my @call_style :Field :All('call_style');
=item contexts
A hash of the contexts that the command may be called from. This needs to
be written up much better in a separate section, as it is very complicated.
B<contexts> will only accept hash type values.
=cut
my @contexts :Field
:All('contexts')
:Type('Hash');
=item parameters
A hash of parameter objects that the command accepts.
B<parameters> will only contain hash values.
=cut
my @parameters :Field
:Type('hash')
:Arg('name'=>'parameters', 'default'=> { } )
:Acc('parameters');
=item required
A hash containing the names of the required parameters.
B<required> will only contain HASH values.
=cut
my @required :Field
:Type('HASH')
:Arg('name'=>'required', 'default'=> { } )
:Acc('required');
=item cl_options
These are command line options that will be issued every time the
command is called. They will begin the value returned by
BuildCommandLine. Make sure that they are not available as
parameters for this command. There is no checking for
duplicates and that will likely cause errors.
B<cl_options> should only contain scalar values.
=cut
my @cl_options :Field
# :Type('scalar')
:All('cl_options');
# Standard class utils are inherited
=back
=head2 METHODS
These methods assist Package authors in common functioanlity needed to support
a command. In some cases they are used internally by other parts of the
Agent::TCLI system.
=over
=item Usages ( context )
Get a list of how this command is called in the given context.
A command may be aliased to several different terms in a given context
lib/Agent/TCLI/Command.pm view on Meta::CPAN
}
return( %opt );
}
=item BuildCommandLine( <param_hash>, <with_cmd> )
Returns a hash keyed on parameter after the arguments have been parsed
by Getopt::Lucid and validated by FormValidator::Simple as per the constraints
specified in the Parameter or Command definitions.
Will respond itself if there is an error and return nothing.
Takes the POE Kernel, the Request, and the Package as args.
=cut
sub BuildCommandLine {
my ($self, $param_hash, $with_cmd ) = @_;
my $command_line = $with_cmd ? $self->command." " : '';
$command_line .= $self->cl_options." " if defined($self->cl_options);
foreach my $param (sort keys %{$param_hash} )
{
my $cp = $self->parameters->{$param}->BuildCommandParam($param_hash)
if ( defined($self->parameters->{$param} ) );
# We'll get a empty string for nothing to set, don't add extra space.
$command_line .= $cp." " if ($cp);
}
chop($command_line);
$self->Verbose("BuildCommandLine: cl($command_line) ",2);
return ($command_line);
}
1;
#__END__
=back
=head3 INHERITED METHODS
This module is an Object::InsideOut object that inherits from Agent::TCLI::Base. It
inherits methods from both. Please refer to their documentation for more
details.
=head1 AUTHOR
Eric Hacker E<lt>hacker at cpan.orgE<gt>
=head1 BUGS
When naming commands in the preinit commands hash or loading from loadyaml()
it is easy to accidentally
duplicate names and cause commands not to load. The author expects that when he
makes this a habit, he'll try to fix it by doing something better than a loading
a hash with no validation.
Most command packages process args in an eval statement which will sometimes
return rather gnarly detailed traces back to the user. This is not a security issue
because open source software is not a black box where such obscurity might
be relied upon (albeit ineffectively), but it is a bug.
SHOULDS and MUSTS are currently not always enforced.
Test scripts not thorough enough.
Probably many others.
=head1 LICENSE
Copyright (c) 2007, Alcatel Lucent, All rights resevred.
This package is free software; you may redistribute it
and/or modify it under the same terms as Perl itself.
=cut
( run in 3.539 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )