with
qw(
MooX::Params::CompiledValidators
)
;
our
$VERSION
=
'2.00'
;
sub
rpcplugin_tag {
my
$full_name
=
ref
(
$_
[0]) ?
ref
(
$_
[0]) :
$_
[0];
(
my
$proto
=
$full_name
) =~ s{.*::}{};
return
"\L${proto}"
;
}
sub
dispatch_builder {
my
$self
=
shift
;
$self
->validate_positional_parameters(
[
$self
->parameter(
endpoint
=>
$self
->Required, {
store
=> \
my
$endpoint
}),
$self
->parameter(
publish
=>
$self
->Required, {
store
=> \
my
$publish
}),
$self
->parameter(
arguments
=>
$self
->Optional, {
store
=> \
my
$arguments
}),
$self
->parameter(
settings
=>
$self
->Optional, {
store
=> \
my
$settings
}),
],
\
@_
);
$publish
//=
'config'
;
if
(
$publish
eq
'config'
) {
return
sub
{
$self
->app->
log
(
debug
=>
"[build_dispatch_table_from_config]"
);
my
$dispatch_builder
= Dancer2::RPCPlugin::DispatchFromConfig->new(
plugin_object
=>
$self
,
plugin
=>
$self
->rpcplugin_tag,
config
=>
$settings
,
endpoint
=>
$endpoint
,
);
return
$dispatch_builder
->build_dispatch_table();
};
}
elsif
(
$publish
eq
'pod'
) {
return
sub
{
$self
->app->
log
(
debug
=>
"[build_dispatch_table_from_pod]"
);
my
$dispatch_builder
= Dancer2::RPCPlugin::DispatchFromPod->new(
plugin_object
=>
$self
,
plugin
=>
$self
->rpcplugin_tag,
packages
=>
$arguments
,
endpoint
=>
$endpoint
,
);
return
$dispatch_builder
->build_dispatch_table();
};
}
return
$publish
;
}
sub
partial_method_lister {
my
$self
=
shift
;
$self
->validate_parameters(
{
$self
->parameter(
protocol
=>
$self
->Required, {
store
=> \
my
$protocol
}),
$self
->parameter(
endpoint
=>
$self
->Required, {
store
=> \
my
$endpoint
}),
$self
->parameter(
methods
=>
$self
->Required, {
store
=> \
my
$methods
}),
},
{
@_
}
);
my
$lister
= Dancer2::RPCPlugin::DispatchMethodList->new();
$lister
->set_partial(
protocol
=>
$protocol
,
endpoint
=>
$endpoint
,
methods
=>
$methods
,
);
return
$lister
;
}
sub
code_wrapper {
my
$self
=
shift
;
$self
->validate_positional_parameters(
[
$self
->parameter(
config
=>
$self
->Required, {
store
=> \
my
$config
}) ],
\
@_
);
return
$config
->{code_wrapper}
?
$config
->{code_wrapper}
:
sub
{
my
$code
=
shift
;
my
$pkg
=
shift
;
$code
->(
@_
);
};
}
1;