Доброго в�ем
¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !
DBIx::Mojo::Template - Render SQL statements by Mojo::Template
0.061
use DBIx::Mojo::Template;
my $dict = DBIx::Mojo::Template->new(__PACKAGE__,mt=>{tag_start=>'%{', tag_end=>'%}',});
my $sql = $dict->{'foo'}->render(table=>'foo', where=> 'where id=?');
# or same
my $sql = $dict->render('bar', where=> 'where id=?');
__DATA__
@@ foo?cache=1
%# my foo statement with prepare_cached (model sth)
select *
from {% $table %}
{% $where %}
my $dict = DBIx::Mojo::Template->new('Foo::Bar', vars=>{...}, mt=>{...})
where arguments:
$pkg (string)
Package name, where __DATA__ section SQL dictionary. Package must be loaded (use/require) before!
vars (hashref)
Hashref of this dict templates variables. Vars can be merged when render - see #render.
mt (hashref)
For Mojo::Template object attributes. See Mojo::Template#ATTRIBUTES.
mt=>{ line_start=>'+', }
Defaults <mt> attrs:
mt=> {vars => 1, prepend=>'no strict qw(vars); no warnings qw(uninitialized);',}
data (arrayref) - optional
Define extra data files for dictionary. Absolute or relative to path of the module $pkg file point.
Merge ditcs packages to one. Arguments same as #new.
DBIx::Mojo::Template->singleton('Foo');
my $dict = DBIx::Mojo::Template->singleton('Bar');
Render template dict key.
my $sql = $dict->render($key, var1=>..., var2 => ...,);
Each dict item is a object DBIx::Mojo::Statement with one method render
:
my $sql = $dict->{'key foo'}->render(bar=>'baz', ...);
Same as #new but returns unblessed hashref dict.
Михаил Че (Mikhail Che), <mche[-at-]cpan.org>
Please report any bugs or feature requests at https://github.com/mche/DBIx-Mojo-Template/issues. Pull requests also welcome.
Copyright 2016 Михаил Че (Mikhail Che).
This module is free software; you can redistribute it and/or modify it under the term of the Perl itself.