-
-
19 Dec 2021 02:26:57 UTC
- Distribution: Yancy
- Module version: 1.088
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (17)
- Testers (48 / 0 / 2)
- Kwalitee
Bus factor: 1- 77.17% Coverage
- License: perl_5
- Perl: v5.16.0
- Activity
24 month- Tools
- Download (1.34MB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 11 contributors-
Boris Däppen
-
Ed J
-
Erik Johansen
-
flash548
-
Josh Rabinowitz
-
Mohammad S Anwar
-
Pavel Serikov
-
Rajesh Mallah
-
Roy Storey
-
William Lindley
-
Wojtek Bażant
NAME
Yancy::Model - Model layer for Yancy apps
VERSION
version 1.088
SYNOPSIS
# XXX: Allow using backend strings my $model = Yancy::Model->new( backend => $backend ); my $schema = $model->schema( 'foo' ); my $id = $schema->create( $data ); my $count = $schema->delete( $id ); my $count = $schema->delete( $where ); my $count = $schema->set( $id, $data ); my $count = $schema->set( $where, $data ); my $item = $schema->get( $id ); my ( $items, $total ) = $schema->list( $where, $opts ); for my $item ( @$items ) { } my $success = $row->set( $data ); my $success = $row->delete(); my $data = $row->to_hash;
DESCRIPTION
NOTE: This module is experimental and its API may change before Yancy v2!
Yancy::Model is a framework for your business logic. Yancy::Model contains a number of schemas, Yancy::Model::Schema objects. Each schema contains a number of items, Yancy::Model::Item objects.
For information on how to extend this module to add your own schema and item methods, see Yancy::Guides::Model.
ATTRIBUTES
backend
A Yancy::Backend object.
namespaces
An array of namespaces to find Schema and Item classes. Defaults to
[ 'Yancy::Model' ]
.log
A Mojo::Log object to log messages to.
METHODS
new
Create a new model with the given backend. In addition to any "ATTRIBUTES", these options may be given:
- schema
-
A JSON schema configuration. By default, the information from "read_schema" will be merged with this information. See "Documenting Your Schema" in Yancy::Guides::Schema for more information.
- read_schema
-
Read the backend database information to build the schema information. Enabled by default. Set to a false value to disable.
find_class
Find a class of the given type for an object of the given name. The name is run through "camelize" in Mojo::Util before lookups.
unshift @{ $model->namespaces }, 'MyApp'; # MyApp::Schema::User $class = $model->find_class( Schema => 'user' ); # MyApp::Item::UserProfile $class = $model->find_class( Item => 'user_profile' );
If a specific class cannot be found, a generic class for the type is found instead.
# MyApp::Schema $class = $model->find_class( Schema => 'not_found' ); # MyApp::Item $class = $model->find_class( Item => 'not_found' );
read_schema
Read the schema from the "backend" and prepare schema objects using "find_class" to find the correct classes.
schema
Get or set a schema object.
$model = $model->schema( user => MyApp::Model::User->new ); $schema = $model->schema( 'user' );
json_schema
Get the JSON Schema for every attached schema.
schema_names
Get a list of all the schema names.
SEE ALSO
AUTHOR
Doug Bell <preaction@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 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.
Module Install Instructions
To install Yancy, copy and paste the appropriate command in to your terminal.
cpanm Yancy
perl -MCPAN -e shell install Yancy
For more information on module installation, please visit the detailed CPAN module installation guide.