NAME
MojoX::Authentication::Util
SYNOPSIS
use Moo;
use MojoX::Authentication::Util qw< coercer_for >;
has foo => (is => 'ro', coerce => coercer_for(foo => 'Some::Class'));
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.
ANYTHING ELSE (INCLUDING AUTHOR, COPYRIGHT AND LICENSE)
See documentation for MojoX::Authentication.