Agent-TCLI
view release on metacpan or search on metacpan
lib/Agent/TCLI/Control.pm view on Meta::CPAN
:All('id');
=item registered_commands
The collection of registered_commands in the control library. Commands may
not be set, but must added with the register method.
=cut
my @registered_commands :Field :Get('registered_commands');
my @starts :Field :Get('starts');
my @stops :Field :Get('stops');
my @handlers :Field :Get('handlers');
my @start_time :Field
:Get('start_time');
my @user :Field :All('user')
:Type('Agent::TCLI::User');
my @packages :Field :All('packages');
#my @alias :Field :All('alias');
=item auth
Authorization for the user for this control. Must be separate from the
auth in the user object since that might not be the only factor at all times.
=cut
my @auth :Field
:All('auth');
=item type
Type of conversation. MUST be one of these values:
B<instant> => one time (or not specified)
B<chat> => peer to peer chat
B<group> => group chatroom
=cut
my @type :Field( 'All' => 'type' );
=item context
Contains the context of the current Command application for the control.
=cut
my @context :Field
:Type('Array')
:Arg('Name' => 'context', 'Default' => ['ROOT'] )
:Acc('context');
=item owner
Contains the owning session of the control. This allows the control to be
passed around between sessions and whatever session that has it can
send back to the top level originating session.
=cut
my @owner :Field( 'All' => 'owner' );
=item prompt
The promt that the control is displaying, when appropriate.
=cut
my @prompt :Field :All('prompt');
=item local_address
The local IP address of the system
=cut
my @local_address :Field
:All('local_address');
=item hostname
The hostname being used by the control.
=cut
my @hostname :Field
:All('hostname');
=item poe_debug
A flag to set whether to enable poe debugging if installed
=cut
my @poe_debug :Field
:All('poe_debug');
# Holds our session data. Made weak per Merlyn
# http://poe.perl.org/?POE_Cookbook/Object_Methods.
# We also don't take session on init.
#my @session :Field
# :Get('session')
# :Weak;
# Standard class utils are inherited
=back
=head2 METHODS
=over
=cut
sub _preinit :Preinit {
my ($self,$args) = @_;
$args->{'session'} = POE::Session->create(
object_states => [
$self => [qw(
_start
_stop
_shutdown
lib/Agent/TCLI/Control.pm view on Meta::CPAN
$self->Verbose( "Execute: Input($input) ",2);
my (@args,$request);
# is input a request object or plaintext?
if (ref($input) =~ /Request/)
{
$request = $input;
$input = $request->input;
$self->Verbose( "Execute: Request ".$request->dump(1),4);
$self->Verbose( "Execute: input from Request ($input)",2,\$input);
# Here we need to extract the command for FindCommand
# Odds are the request doesn't have args or command populated
# if it was built outside of the Control.
if ( defined($request->args) )
# Hmm, someone thinks they're smarter than the Control at
# parsing. OK, we'll take that. Later we'll use the real args.
{
@args = reverse( @{$request->command} );
}
# add self to sender/postback stack so that we can put ourself
# into PostResponse to Transport to handle many contrls per transport
# Or should I just stuff that into the request at the Transport
# Well, what if there isn't a request yet at the transport?
# Either the request exists or it will come from the control....
# Or just make the stateful transports create a request...
# I think that is more elegant.
# Scratch all this.
}
$self->Verbose( "Execute: args",2,\@args);
# Now get args from input.
if ( ! @args )
{
# TODO Still need a better parser.
# Parsewords chokes on single singlequotes.
$input =~ s/'//;
# parsewords also parses whitespace at the beginning poorly.
$input =~ s/^\s*//;
# Parsewords doesn't handle trailing backslashes well.
$input =~ s/\\$//;
@args = shellwords($input);
}
# substitute for help
$args[0] = 'help' if ($args[0] eq '?');
# # The command is broken down into a context, a command, and args.
# # The context helps find the command to execute and usually
# # remains the same between transactions unless changed by the user.
# # Context may be up to five layers deep. A single command may be
# # usable in more than one context, or even in all.
#
# # The command is sent as the first arg in @args.
#
# # Each command gets the following to execute:
# # $postback -> to send the response
# # \@args -> typically the user input in an array
# # $input -> the original user input
# # $thread -> the thread object for the user's session
# # The current context is stored in the $thread as an array but is
# # retrievable as a string as well.
#
# # Some commands merely establish context. Such as 'enable' in a Cisco
# # CLI. Though enable may require additional args. A default method/session
# # of the Agent::TCLI::Package::Base class called establish_context can handle
# # the simple case of setting context and confirming for the user.
#
# # $args[0] will always be the command word to execute, but may have
# # not been the first word entered if the command is nested deep in a
# # context. If a command needs to determine exactly how it was called
# # then it needs to reparse $input.
my ($cmd, $context, $txt, $code) = $self->FindCommand(\@args);
unless ($code == 404)
{
$self->Verbose("Execute: Executing cmd(".$cmd->name.
") for ".$id[$$self]." \n");
# Now actually execute the command
if ( ref($request) =~ /Request/ )
{
if ( !defined($request->args) || $request->depth_args == 0 )
{
$request->args( \@args );
$request->command( $context );
$self->Verbose( "Execute: Request post FindCommand".$request->dump(1),3);
}
# The response may bypass the Control's AsYouWished, and go
# directly back to the Transport if that is what is $request(ed)
if ( $cmd->call_style eq 'sub')
{
# Subs can't handle request objects.
my (@rargs, $rinput);
# subs want the command in the @rargs
push( @rargs, $request->command->[0], $request->args );
# Make sure there is input, just in case....
$rinput = defined($request->input) ? $request->input :
join(' ',$request->command->[0],$request->args);
# do it
($txt, $code) = $self->DoSub($cmd, \@rargs, $rinput );
$request->Respond( $kernel, $txt, $code);
return;
}
elsif ( $cmd->call_style eq 'state')
{
$self->Verbose("Execute: Executing state ".$cmd->handler." \n");
$kernel->yield( $cmd->handler => $request );
return;
}
elsif ( $cmd->call_style eq 'session')
{
$self->Verbose("Execute: Executing session ".$cmd->command.
( run in 2.054 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )