Clutch
view release on metacpan or search on metacpan
Revision history for Perl extension Clutch
0.05 2012/04/11
- add cascade method
- code refactoring
- some docs fixed
- Clutch::Utils rename to Clutch::Utils and hide from pause
0.04 2012/03/22
- change protocol
- support request_multi(_background)
- remove Clutch::Admin
- no use DWR
MANIFEST This list of files
MANIFEST.SKIP
META.yml
PROTOCOL
README
t/000_load.t
t/001_basic.t
t/002_request_background.t
t/003_request_multi.t
t/004_request_background_multi.t
t/005_cascade.t
t/lib/Worker.pm
xt/perlcritic.t
xt/pod.t
lib/Clutch/Worker.pm view on Meta::CPAN
our @EXPORT = qw(
new
run
setup_listener
accept_loop
handle_connection
register_function
dispatch
do_request
do_request_background
cascade
);
my $FUNCTIONS = +{};
my $CONTEXT;
sub new {
my $class = shift;
my %args = @_ == 1 ? %{$_[0]} : @_;
%args = (
lib/Clutch/Worker.pm view on Meta::CPAN
my $res = $code ? "OK" : "ERROR: unknow function";
Clutch::Utils::write_all($conn, Clutch::Utils::make_response($res), $self->{timeout}, $self);
$conn->close();
$code && $code->($req->{args});
return;
}
sub cascade {
my ($function, $args) = @_;
my $code = $CONTEXT->{functions}->{$function};
$code ? ($code->($args) || '') : "ERROR: unknow function";
}
sub register_function ($$) { ## no critic
my ($function, $code) = @_;
$FUNCTIONS->{$function} = $code;
}
lib/Clutch/Worker.pm view on Meta::CPAN
client process specific this functin name.
=item $callback_coderef
client process call the function, execute thid $callback_coderef.
$callback_coderef's first argument is a client request parameter.
=back
=head2 cascade($function_name, $args);
call self worker function.
=over
=item $function_name
worker process function name.
=item $args
t/005_cascade.t view on Meta::CPAN
test_tcp(
client => sub {
my ($port, $server_pid) = @_;
my $client = Clutch::Client->new(
servers => ['127.0.0.1:'.$port]
);
my $res;
{
$res = $client->request('cascade_root');
note $res;
is $res, 'cascaded';
}
kill 'TERM', $server_pid;
},
server => sub {
my $port = shift;
Worker->new(
{
address => '127.0.0.1:'.$port,
}
t/lib/Worker.pm view on Meta::CPAN
register_function(
'foo' => sub {
my $args = shift;
note 'execute';
return;
}
);
register_function(
'cascade_root' => sub {
my $args = shift;
my $res = cascade('cascade_sub', $args);
return $res;
}
);
register_function(
'cascade_sub' => sub {
my $args = shift;
return 'cascaded';
}
);
1;
( run in 0.707 second using v1.01-cache-2.11-cpan-49f99fa48dc )