CONTENTS
#NAME
Yancy::Model - Model layer for Yancy apps
#VERSION
version 1.081
#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
#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' );
#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.