Agent-TCLI

 view release on metacpan or  search on metacpan

lib/Agent/TCLI/Control.pm  view on Meta::CPAN

		else
		{
			$thisdepth = -1;
		}
	}

	# Might use thisdepth later to determine better response.
	if ( $thisdepth < 0 )
	{
			$txt .= "Command '".join(' ',@{$args})."' not found";
			$code = 404;
			$cmd = undef;
			$self->Verbose("FindCommand: ".$txt.
				") code ($code) thisdepth(".$thisdepth.") \n");
			$self->Verbose("FindCommand: working c array \n",2,\@c);
			$self->Verbose("FindCommand: current registered_commands hash \n",2,$registered_commands[$$self]);
	}

	unless ( $txt )
	{
		$self->Verbose("FindCommand: thisdepth($thisdepth) \n",3,\@c);

lib/Agent/TCLI/Control.pm  view on Meta::CPAN

	if ( %cmds )
	{

		# always return something defined.
		$txt = '';
		$code = 200;
	}
	else
	{
		$txt .= "Commands not found";
		$code = 404;
#		%cmds = undef;
		$self->Verbose("ListCommands: Whoooops! \n",1,\@aliases);
	}

	$self->Verbose("ListCommand: cmds(".(scalar keys %cmds).") txt(".$txt.") \n",1);
	return(\%cmds, $txt, $code);
}

=item RegisterCommand

lib/Agent/TCLI/Control.pm  view on Meta::CPAN

#	# 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 )
			{

lib/Agent/TCLI/Control.pm  view on Meta::CPAN

#      @_[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.
#

lib/Agent/TCLI/Control.pm  view on Meta::CPAN

#				}
#			}
#			elsif ( $self->can( $attr )  )
#			{
#		  		$txt = $what.": #!undefined";
#				$code = 200;
#			}
#			else # should get here, but might if parameter error.
#		  	{
#  				$txt = $what.": #!ERROR does not exist";
#  				$code = 404;
#  			}
#		}
#	}
#
#	# if we didn't find anything at all, then a 404 is returned
#  	if (!defined($txt) || $txt eq '' )
#  	{
#  		$txt = $what.": #!ERROR not found";
#  		$code = 404;
#  	}
#
#	$request->Respond($kernel, $txt, $code);
#}
#
#=item settings
#
#This POE event handler executes the set commands.
#
#=cut

lib/Agent/TCLI/Control.pm  view on Meta::CPAN

#				return;
#			}
#			$txt .= "Set ".$attr." to ".$param->{$attr}." \n";
#			$code = 200;
#		}
#	}
#
#  	if (!defined($txt) || $txt eq '' )
#  	{
#  		$txt = "Invalid: ".join(', ',keys %{$param} );
#  		$code = 404;
#  	}
#
#	$request->Respond($kernel, $txt, $code);
#}

=item print_context

An object method to get the current context in string form. It has no parameters.

=cut

lib/Agent/TCLI/Package/Base.pm  view on Meta::CPAN

      @_[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.

lib/Agent/TCLI/Package/Base.pm  view on Meta::CPAN

				}
			}
			elsif ( $self->can( $attr )  )
			{
		  		$txt = $what.": #!undefined";
				$code = 200;
			}
			else # should get here, but might if parameter error.
		  	{
  				$txt = $what.": #!ERROR does not exist";
  				$code = 404;
  			}
		}
	}

	# if we didn't find anything at all, then a 404 is returned
  	if (!defined($txt) || $txt eq '' )
  	{
  		$txt = $what.": #!ERROR not found";
  		$code = 404;
  	}

	$request->Respond($kernel, $txt, $code);
}

=item settings

This POE event handler executes the set commands.

=cut

lib/Agent/TCLI/Package/Base.pm  view on Meta::CPAN

				return;
			}
			$txt .= "Set ".$attr." to ".$param->{$attr}." \n";
			$code = 200;
		}
	}

  	if (!defined($txt) || $txt eq '' )
  	{
  		$txt = "Invalid: ".join(', ',keys %{$param} );
  		$code = 404;
  	}

	$request->Respond($kernel, $txt, $code);
}

sub GetControl {
	my ($self, $id ) = @_;
	return ( $controls[$$self]->{$id}{'control'} )
		if defined( $controls[$$self]->{$id}{'control'} );
	return (0);



( run in 1.243 second using v1.01-cache-2.11-cpan-39bf76dae61 )