The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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.