-
-
31 Mar 2018 17:45:13 UTC
- Distribution: DBIx-Mojo-Template
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (1)
- Testers (722 / 2 / 0)
- Kwalitee
Bus factor: 1- 88.17% Coverage
- License: artistic_2
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (6.59KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
++ed by:1 non-PAUSE userand 1 contributors- ÐÐ¸Ñ Ð°Ð¸Ð» Че (Mikhail Che) <mche[-at-]cpan.org>
- Dependencies
- Clone
- Hash::Merge
- Mojolicious
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
Доброго всем
DBIx::Mojo::Model
¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !
NAME
DBIx::Mojo::Model - base class for DBI models with templating statements by Mojo::Template.
SINOPSYS
Init once base singleton for process with dbh and (optional) template vars:
use DBIx::Mojo::Model; DBIx::Mojo::Model->singleton(dbh=>$dbh, template_vars=>$t);
In child model must define SQL dict in __DATA__ of model package:
package Model::Foo; use Mojo::Base 'DBIx::Mojo::Model'; sub new { state $self = shift->SUPER::new(mt=>{tag_start=>'{%', tag_end=>'%}'}, @_); } sub foo { my $self = ref $_[0] ? shift : shift->new; $self->dbh->selectrow_hashref($self->sth('foo', where => 'where id=?',), undef, (shift)); } __DATA__ @@ foo?cached=1 %# my foo statement with prepare_cached select * from foo {% $where %} ;
In controller:
... has model => sub { require Model::Foo; Model::Foo->new }; sub actionFoo { my $c = shift; my $foo = $c->model->foo($c->param('id')); ... }
ATTRIBUTES
dbh
dict
DBIx::Mojo::Template object. If not defined then will auto create from __DATA__ current model package.
Model::Foo->new(dict=>DBIx::Mojo::Template->new('Model::Foo', ...), ...)
mt
Hashref Mojo::Template object attributes. Will passed to
Mojo::Template->new
then dict auto createtemplate_vars
Hashref variables applies in statement templates.
dbi_cache_st
Boolean switch: 1(true) - use DBI caching ($dbh->prepare_cached) and 0(false) overvise this module caching.
The statement must has defined
cached
param:@@ foo query name?cached=1 select ...
Defaults is true for save statement inside DBIx::Mojo::Statement object atribute
sth
.METHODS
new
Define or copy/merge attributes from
singleton
.singleton
Initialize default attributes for child model modules. Mostly
dbh
andtemplate_vars
sth
This is main method.
First input arg is dict statement name, next args
key => val
are template variables. Return DBI prepared (cached if param 'cached' is true) statement.Templates
Body of template statement get as:
$mFoo->dict->{'foo'}->sql
Templates name can has additional params as ulr query:
@@ foo.bar/baz?a=156&b=c ...
then model object the name of statement is url path and query is param:
$mFoo->dict->{'foo.bar/baz'}->param->{b} # 'c'
AUTHOR
Михаил Че (Mikhail Che),
<mche[-at-]cpan.org>
BUGS / CONTRIBUTING
Please report any bugs or feature requests at https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/issues. Pull requests also welcome.
COPYRIGHT
Copyright 2016 Mikhail Che.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install DBIx::Mojo::Template, copy and paste the appropriate command in to your terminal.
cpanm DBIx::Mojo::Template
perl -MCPAN -e shell install DBIx::Mojo::Template
For more information on module installation, please visit the detailed CPAN module installation guide.