Agent-TCLI
view release on metacpan or search on metacpan
lib/Agent/TCLI/Package/Base.pm view on Meta::CPAN
if (!defined( $self->name ))
{
$self->Verbose("_start: OIO not done re-starting");
$kernel->yield('_start');
# $kernel->delay('_start', 1 );
return;
}
$self->Verbose("_start: ".$self->name()." starting");
# There is only one command object per TCLI
$kernel->alias_set($self->name);
}
# This POE event handler is used to initiate a shutdown of the Control.
sub _shutdown :Cumulative {
my ($kernel, $self,) =
@_[KERNEL, OBJECT,];
$self->Verbose("_shutdown:base ".$self->name." shutting down");
$self->Verbose("shutdown:base deleting wheels ",2);
foreach my $wheel ( keys %{ $wheels[$$self] } )
{
$self->SetWheel($wheel);
}
foreach my $control ( keys %{ $controls[$$self] } )
{
$self->SetControl($control);
}
# clear all alarms you might have set
$kernel->alarm_remove_all();
return ("_shutdown:base ".$self->name )
}
#This POE event handler is called when POE stops a Package.
#The B<_stop> method is :Cumulative within OIO.
sub _stop :Cumulative {
my ($kernel, $self,) =
@_[KERNEL, OBJECT,];
$self->Verbose("_stop: ".$self->name." stopping");
return($self->name.":_stop complete ");
}
#Just a placeholder that does nothing but collect unhandled child events
#to keep them out of default.
sub _child {
my ($kernel, $self, $session, $id, $error) =
@_[KERNEL, OBJECT, SESSION, ARG1, ARG2 ];
$self->Verbose("child: pid($id) ");
}
=item establish_context
This POE event handler is the primary way to set context with a command.
Just about any command that has subcommands will use this method as it's handler.
An exception would be a command that sets an single handler to process all
subcoammnds/args using the 'A*' context. See the Eliza package for an example of
how to establish that type of context.
=cut
sub establish_context {
my ($kernel, $self, $sender, $request, ) =
@_[KERNEL, OBJECT, SENDER, ARG0, ];
$self->Verbose("establish_context: ".$self->name." for request(".
$request->id().")");
my $txt;
# if we have args, then the command is invalid
if ( $request->depth_args > 0 )
{
$txt .= "Invalid input: ".$request->input;
$self->Verbose("establish_context: Invalid input (".$request->input.")" );
$request->Respond($kernel, $txt, 404) if $txt;
return;
}
# we don't know how deep we're in already. So we'll force a full context shift.
# by sending the entire command array back, which is revesred.
my @context = reverse (@{$request->command});
# We don't actualy set the controls context, but let change context do that.
# It will also inform the user of change.
# Post context back to sender (Control)
$kernel->call( $sender => 'ChangeContext' => $request, \@context );
$self->Verbose("establish_context: setting context to "
.join(' ',@context)." ",2);
}
=item show
This POE event handler is the default show for packages.
It will accept an argument for the setting to show. It will also take an
argument of all or * and show all settings.
The parameter must be defined in the show Command entry's parameters or it will
not be shown. There must also be a OIO Field defined with the same name.
One may write their own show method if this is not sufficient.
One must still define the show Command within one's package to use this. One
must also load the show event handler in the Package's session.
=cut
sub show {
my ($kernel, $self, $sender, $request, ) =
@_[KERNEL, OBJECT, SENDER, ARG0, ];
$self->Verbose("show: request(".$request->id.") ",2);
my ($txt, $code, $what, $var);
# calling with show as a command, that is the handler for show is show.
if ( $request->command->[0] eq 'show' ) # cmd1 show arg
# cmd1 attacks show <arg>
{
( run in 0.473 second using v1.01-cache-2.11-cpan-39bf76dae61 )