Dancer-Plugin-Resource
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Dancer/Plugin/Resource.pm view on Meta::CPAN
if ( my $p = $options{params} ) {
$p = ref $p ? $p : [$p];
$params = join '/', map ":${_}", @{$p};
}
else {
$params = ":${singular_resource}_id";
}
my ($package) = caller;
# main resource endpoints
# CRUD
_post(
_endpoint(
path => $plural_resource,
params => '',
verbs => [qw/POST create/],
function => $singular_resource
)
);
_get(
_endpoint(
path => $plural_resource,
params => $params,
verbs => [qw/GET get read/],
loader => $options{load},
function => $singular_resource
)
);
_put(
_endpoint(
path => $plural_resource,
params => $params,
verbs => [qw/PUT update/],
loader => $options{load},
function => $singular_resource
)
);
_del(
_endpoint(
path => $plural_resource,
params => $params,
verbs => [qw/DELETE delete/],
loader => $options{load},
function => $singular_resource
)
);
_get(
_endpoint(
path => $plural_resource,
params => '',
verbs => [qw/INDEX index/],
loader => $options{load_all},
function => $singular_resource
)
);
# member routes are actions on the given id. ie /users/:user_id/foo
for my $member (@{$options{member}}) {
my $path = "${plural_resource}/$params/${member}";
my $member_param = "";
_post(
_endpoint(
path => $path,
params => '',
verbs => [qw/POST create/],
loader => $options{load},
function => "${singular_resource}_${member}"
)
);
_get(
_endpoint(
path => $path,
params => $member_param,
verbs => [qw/GET get read/],
loader => $options{load},
function => "${singular_resource}_${member}"
)
);
_put(
_endpoint(
path => $path,
params => $member_param,
verbs => [qw/PUT update/],
loader => $options{load},
function => "${singular_resource}_${member}"
)
);
_del(
_endpoint(
path => $path,
params => $member_param,
verbs => [qw/DELETE delete/],
loader => $options{load},
function => "${singular_resource}_${member}"
)
);
}
# collection routes are actions on the collection. ie /users/foo
for my $collection (@{$options{collection}}) {
my $path = "${plural_resource}/${collection}";
_post(
_endpoint(
path => $path,
params => '',
verbs => [qw/POST create/],
loader => $options{load_all},
function => "${plural_resource}_${collection}"
)
);
_get(
_endpoint(
path => $path,
params => '',
verbs => [qw/GET get read/],
loader => $options{load_all},
function => "${plural_resource}_${collection}"
)
);
_put(
_endpoint(
path => $path,
params => '',
verbs => [qw/PUT update/],
loader => $options{load_all},
function => "${plural_resource}_${collection}"
)
);
_del(
_endpoint(
path => $path,
params => '',
verbs => [qw/DELETE delete/],
loader => $options{load_all},
function => "${plural_resource}_${collection}"
)
);
}
# save every defined resource if it is referred as a parent in a nested child resource
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.107 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )