Yancy::Model - Model layer for Yancy apps
version 1.085
# 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;
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.
A Yancy::Backend object.
An array of namespaces to find Schema and Item classes. Defaults to [ 'Yancy::Model' ].
[ 'Yancy::Model' ]
A Mojo::Log object to log messages to.
Create a new model with the given backend. In addition to any "ATTRIBUTES", these options may be given:
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 the backend database information to build the schema information. Enabled by default. Set to a false value to disable.
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 the schema from the "backend" and prepare schema objects using "find_class" to find the correct classes.
Get or set a schema object.
$model = $model->schema( user => MyApp::Model::User->new ); $schema = $model->schema( 'user' );
Get the JSON Schema for every attached schema.
Get a list of all the schema names.
Yancy::Guides::Model
Doug Bell <preaction@cpan.org>
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.
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.