Alien-Taco
view release on metacpan or search on metacpan
lib/Alien/Taco.pm view on Meta::CPAN
my $in = shift;
my $out = shift;
return new Alien::Taco::Transport(
in => $in,
out => $out,
filter_single => ['_Taco_Object_' => sub {
return new Alien::Taco::Object($self, shift);
}],
);
}
# _interact(\%message)
#
# General interaction method. This is the internal method used to
# implement the main Taco methods.
#
# The given message is filtered for objects and then sent using the
# Alien::Taco::Transport. If the response is a result then it is
# returned. If the response is an exception, then an exception is
# raised.
sub _interact {
my $self = shift;
my $message = shift;
my $xp = $self->{'xp'};
$xp->write($message);
my $res = $xp->read();
my $act = $res->{'action'};
if ($act eq 'result') {
return @{$res->{'result'}}
if wantarray and 'ARRAY' eq ref $res->{'result'};
return $res->{'result'};
}
elsif ($act eq 'exception') {
die 'received exception: ' . $res->{'message'};
}
else {
die 'received unknown action: ' . $act;
}
}
=back
=head2 Taco Methods
The methods in this section allow the corresponding Taco actions to be sent.
=over 4
=item call_class_method('class_name', 'function_name',
[args => \@args], [kwargs => \%kwargs])
Invoke a class method call within the Taco server script, returning the
result of that method. The context (void / scalar / list)
is detected and sent as a parameter. Since Perl subroutine arguments
are expanded into a list, the I<arguments> and I<keyword arguments>
must be given separately.
=cut
sub call_class_method {
my $self = shift;
my $class = shift;
my $name = shift;
my %opts = @_;
return $self->_interact({
action => 'call_class_method',
class => $class,
name => $name,
args => $opts{'args'},
kwargs => $opts{'kwargs'},
context => (defined wantarray ? (wantarray?'list':'scalar') : 'void'),
});
}
=item call_function('function_name', [args => \@args], [kwargs => \%kwargs])
Invoke a function call within the Taco server script, returning the
result of that function. The context (void / scalar / list)
is detected and sent as a parameter. Since Perl subroutine arguments
are expanded into a list, the I<arguments> and I<keyword arguments>
must be given separately.
=cut
sub call_function {
my $self = shift;
my $name = shift;
my %opts = @_;
return $self->_interact({
action => 'call_function',
name => $name,
args => $opts{'args'},
kwargs => $opts{'kwargs'},
context => (defined wantarray ? (wantarray?'list':'scalar') : 'void'),
});
}
# _call_method($number, 'method', [args => \@args], [kwargs => \%kwargs])
#
# Internal method invoked by Alien::Taco::Object instances.
sub _call_method {
my $self = shift;
my $number = shift;
my $name = shift;
my %opts = @_;
return $self->_interact({
action => 'call_method',
number => $number,
name => $name,
args => $opts{'args'},
kwargs => $opts{'kwargs'},
context => (defined wantarray ? (wantarray?'list':'scalar') : 'void'),
});
}
=item construct_object('class', [args => \@args], [kwargs => \%kwargs])
Invoke an object constructor. If successful, this should return
an L<Alien::Taco::Object> instance which references the new object.
The given arguments are passed to the object constructor.
=cut
sub construct_object {
my $self = shift;
my $class = shift;
my %opts = @_;
return $self->_interact({
action => 'construct_object',
class => $class,
args => $opts{'args'},
kwargs => $opts{'kwargs'},
});
}
# _destroy_object($number)
( run in 2.673 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )