NAME
Yancy::Util - Utilities for Yancy
VERSION
version 1.013
SYNOPSIS
use Yancy::Util qw( load_backend );
my $be = load_backend( 'test://localhost', $collections );
use Yancy::Util qw( curry );
my $helper = curry( \&_helper_sub, @args );
use Yancy::Util qw( currym );
my $sub = currym( $object, 'method_name', @args );
DESCRIPTION
This module contains utility functions for Yancy.
SUBROUTINES
load_backend
my $backend = load_backend( $backend_url, $collections );
my $backend = load_backend( { $backend_name => $arg }, $collections );
Get a Yancy backend from the given backend URL, or from a hash reference with a backend name and optional argument. The $collections
hash is the configured collections for this backend.
A backend URL should begin with a name followed by a colon. The first letter of the name will be capitalized, and used to build a class name in the Yancy::Backend
namespace.
The $backend_name
should be the name of a module in the Yancy::Backend
namespace. The $arg
is handled by the backend module. Read your backend module's documentation for details.
See "Database Backend" in Yancy for information about backend URLs and Yancy::Backend for more information about backend objects.
curry
my $curried_sub = curry( $sub, @args );
Return a new subref that, when called, will call the passed-in subref with the passed-in @args
first.
For example:
my $add = sub {
my ( $lop, $rop ) = @_;
return $lop + $rop;
};
my $add_four = curry( $add, 4 );
say $add_four->( 1 ); # 5
say $add_four->( 2 ); # 6
say $add_four->( 3 ); # 7
This is more-accurately called partial application, but curry
is shorter.
currym
my $curried_sub = currym( $obj, $method, @args );
Return a subref that, when called, will call given $method
on the given $obj
with any passed-in @args
first.
See "curry" for an example.
SEE ALSO
AUTHOR
Doug Bell <preaction@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.