NAME
MojoX::Authentication::Util
SYNOPSIS
use Moo;
use MojoX::Authentication::Util qw< coercer_for encode_name >;
has foo => (is => 'ro', coerce => coercer_for(foo => 'Some::Class'));
my $id = join '/', encode_name($provider_name), $uid;
DESCRIPTION
Utility functions for the distribution.
INTERFACE
This module exports the following functions.
coercer_for
use Moo;
has foo => (is => 'ro', coerce => coercer_for(foo => 'Some::Class'));
Generate a function suitable for coerce in a Moo member. The function takes two positional arguments, respectively a name and a class and returns a function accepting a single input argument:
sub ($x) { ... }
The input $x is used as follows:
If it's blessed and supports a method named as name, then it will be called and its output returned by the coercer. In other terms, in this case it's used as a factory object.
Otherwise, if it's blessed, it's assumed to be good as output and returned as-is.
Otherwise, if it's a sub reference then it's called and its output returned by the coercer. In other terms, in this case it's used as a factory function.
As the last resort, the class is
required and itsnewmethod called, passing the input as the only parameter.
decode_name
my $name = decode_name($encoded);
Reverse of "encode_name".
encode_name
my $encoded = encode_name($name);
Encode a provider name so that it never contains a slash, e.g. to put it before a slash in an identifier: characters % and / are replaced by % followed by their code in two hexadecimal digits. Different names always give different encodings.
It is used for the user identifiers kept in the session (see "User identifiers" in MojoX::Authentication::Model) and for the keys of MojoX::Authentication::Model::SAML2's cache, so that providers sharing a cache never share entries.
ANYTHING ELSE (INCLUDING AUTHOR, COPYRIGHT AND LICENSE)
See documentation for MojoX::Authentication.