Agent-TCLI
view release on metacpan or search on metacpan
lib/Agent/TCLI/Request.pm view on Meta::CPAN
:All('sender')
:Type('ARRAY' );
=item postback
The event to post the response back to. It is also the return addressee when
going between agents.
=cut
my @postback :Field
:All('postback')
:Type('ARRAY' );
=item input
The exact, unparsed input string from the user. This might be useful for
some commands, but mostly is ignored. If not provided it should be automatically
generated from the command and args if necessary.
=cut
my @input :Field
:All('input');
=item response_count
A counter that is incremented for every response to this request.
This is updated automatically through the use of the Respond method.
B<response_count> will only accept NUMERIC type values.
=cut
my @response_count :Field :All('response_count')
:Type('NUMERIC' );
=item response_verbose
A setting that determines how much of the request information
is returned with the response. If true, the entire request
will be returned. If false, only the required fields will be.
B<response_verbose> should only contain boolean values.
=cut
my @response_verbose :Field
# :Type('boolean')
:All('response_verbose');
=item Arrays
Attributes that are typed as arrays also support the following mutators for
the lazy:
B<shift_>field<> - works the same as I<shift>, returing the shifted member.
B<unshift_>field<(list)> - works the same as I<unshift>.
B<pop_>field<> - works the same as I<pop>, returing the popped member.
B<push_>field<(list)> - works the same as I<push>.
B<depth_>field<> - returns the curent size of the array.
=item Auto-Attributes
Agent::TCLI::Request has an AutoMethod routine that can create object attributes
on the fly. These all use lower case set_/get_ mutators which differentiates
them from the pre-defined attributes. Since all responses should contain the
original Request object, this is a handy way to pass stateful information
about the Request to the postback handling the response.
For example: $request->set_test('like');
If the new attribute name contains 'array', it is created as an array type
and the array mutators listed above will apply.
=back
=cut
sub _init :Init {
my ($self, $args) = @_;
# Gee, this will make it real easy to 'break' into the request object
# from outside by knowing the ID. That's OK. Nothing to hide here.
$self->set(\@id, ( defined($args->{'id'}) && $args->{'id'} )
? $args->{'id'}
: $$self ) unless ($self->id);
}
=head2 METHODS
=over
=item MakeResponse ( <text>, <code> )
MakeResponse used internally by Respond to create the Response object
to send back to the requestor. The only reason to call MakeResponse
directly would be to add or remove attributes before the Response is
sent.
=cut
sub MakeResponse {
my ($self, $txt, $code) = @_;
# TODO better validation of code
$code = 200 unless defined($code);
my $response = Agent::TCLI::Response->new(
'body' => $txt,
'code' => $code,
'id' => $self->id,
'sender' => [@{$self->sender}],
'postback' => [@{$self->postback}],
'response_count'=>$self->response_count,
);
if ( $self->response_verbose )
{
$response->args($self->args);
$response->input($self->input);
$response->command($self->command);
$response->response_verbose($self->response_verbose);
# copy all the dynamically created fields
$self->Verbose("MakeResponse: can",4, \@{$self->can} );
( run in 1.573 second using v1.01-cache-2.11-cpan-39bf76dae61 )