NAME
Kelp::Util - Kelp general utility functions
SYNOPSIS
use Kelp::Util;
# MyApp::A::b
say Kelp::Util::camelize('a#b', 'MyApp');
# Controller
say Kelp::Util::extract_class('Controller::Action');
# Action
say Kelp::Util::extract_function('Controller::Action');
DESCRIPTION
These are some helpful functions not seen in Plack::Util.
FUNCTIONS
No functions are exported and have to be used with full package name prefix.
camelize
This function accepts a string and a base class. Does three things:
transforms snake_case into CamelCase for class names (with lowercasing)
replaces hashes
#
with Perl package separators::
constructs the class name in similar fasion as "load_class" in Plack::Util
The returned string will have leading +
removed and will be prepended with the second argument if there was no +
.
extract_class
Extracts the class name from a Controller::action
string. Returns undef if no class in the string or the class is main
.
extract_function
Extracts the function name from a string. If there is no class name, returns the entire string. Returns undef for empty strings.
adapt_psgi
Transforms a given Plack/PSGI application (in form of a runner subroutine) to a Kelp route handler. The route handler will take the last argument matched from a pattern and adjust the proper environmental paths of the PSGI standard. This will make the application mostly behave as if it was mounted directly where the route points minus the last placeholder. For example, route /app
will adjust the script name to '/app'
and path info will always be empty, while route /app/>rest
will have the same script name and path info set to whatever was after /app
in the URL (trailing slashes included).
NOTE: having more than one placeholder in the pattern is mostly wasteful, as their matched values will not be handled in any way (other than allowing a varying request path).