Agent-TCLI
view release on metacpan or search on metacpan
lib/Agent/TCLI/Transport/Base.pm view on Meta::CPAN
my $txt = '';
my $code;
# TODO a way to unset/restore defaults....
# lets see how it goes....
foreach my $attr ( keys %{$params} )
{
# special case for verbose.
$attr = 'verbose' if ($attr =~ qr(_verbose));
eval { $self->$attr( $params->{$attr} ) };
if( $@ )
{
$self->Verbose("Set: self->".$attr.'('.$params->{$attr}.' ) got ('.$@.') ');
$txt = "Invalid: $attr => ".$params->{$attr}." !";
$code = 400;
}
else
{
$txt = "Set: $attr => ".$params->{$attr}." ";
$code = 200;
}
if ($request)
{
$self->Verbose('Set: responding txt('.$txt.') code('.$code." )",2);
$request->Respond($kernel, $txt, $code);
}
}
}
=item Show
This POE event handler is may be used by a Transport to enable a Package
to show current settings in the Transport. It currently is not filtering
out anything, so if something should not be shown, either the Transport
needs to implement its own Show, or the Package should apply necessary filters.
B<Show> takes the attribute to show and the Request object as arguments.
=cut
sub Show {
my ($kernel, $self, $attr, $request) =
@_[KERNEL, OBJECT, ARG0, ARG1];
$self->Verbose("Show: $attr ",1);
my $txt = '';
my ($code, $value);
if ($attr eq 'peers')
{
# loop over the users
foreach my $peer ( @{$self->peers} )
{
$txt .= "\nid: ".$peer->id."\nprotocol: ".$peer->protocol.
"\nauth: ".$peer->auth."\npassword: ******\n";
$code = 200;
}
}
elsif ($attr eq 'controls')
{
# loop over the controls
foreach my $control ( keys %{$self->controls} )
{
$txt .= "\nid: ".$control->id."\n";
$code = 200;
}
}
else
{
# lets see how it goes....
eval { $value = $self->$attr };
if( $@ )
{
$self->Verbose("Show: self->$attr got (".$@.') ');
$txt = "Invalid $attr : $@ !";
$code = 400;
}
elsif ( ref($value) )
{
$txt = "$attr is not a scalar. Dumping: \n";
$txt .= pp($value);
$code = 200;
}
else
{
$txt = "$attr => $value ";
$code = 200;
}
}
if ($request)
{
$self->Verbose('Show: responding txt('.$txt.') code('.$code." )",3);
$request->Respond($kernel, $txt, $code);
return;
}
# What do we do if there is no request?
}
=item _default
This POE event handler is used to catch wayard calls to unavailable states. If
verbose is on, it makes it rather obvious in the logs that an event was not
handled.
=cut
sub _default {
my ($kernel, $self, ) =
@_[KERNEL, OBJECT, ];
my $oops = "\n\n\n".
"\t OOOO OOOO PPPPPP SSSSSS ## \n".
"\t OO OO OO OO PP PP SS ## \n".
"\tOO OO OO OO PP PP SS ## \n".
( run in 0.713 second using v1.01-cache-2.11-cpan-d8267643d1d )