Yancy::Util - Utilities for Yancy
version 1.019
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 );
This module contains utility functions for Yancy.
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.
$collections
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.
Yancy::Backend
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.
$backend_name
$arg
See "Database Backend" in Yancy::Help::Config for information about backend URLs and Yancy::Backend for more information about backend objects.
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.
@args
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.
curry
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.
$method
$obj
See "curry" for an example.
Yancy
Doug Bell <preaction@cpan.org>
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.
To install Yancy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yancy
CPAN shell
perl -MCPAN -e shell install Yancy
For more information on module installation, please visit the detailed CPAN module installation guide.