++ed by:

1 non-PAUSE user.

Михаил Че
and 1 contributors

Доброго всем

DBIx::Mojo::Template

¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !

NAME

DBIx::Mojo::Template - Render SQL statements by Mojo::Template

VERSION

0.061

SYNOPSIS

  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 %}

SUBROUTINES/METHODS

new

  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.

singleton

Merge ditcs packages to one. Arguments same as #new.

  DBIx::Mojo::Template->singleton('Foo');
  my $dict = DBIx::Mojo::Template->singleton('Bar');

render

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', ...);

data

Same as #new but returns unblessed hashref dict.

AUTHOR

Михаил Че (Mikhail Che), <mche[-at-]cpan.org>

BUGS / CONTRIBUTING

Please report any bugs or feature requests at https://github.com/mche/DBIx-Mojo-Template/issues. Pull requests also welcome.

LICENSE AND COPYRIGHT

Copyright 2016 Михаил Че (Mikhail Che).

This module is free software; you can redistribute it and/or modify it under the term of the Perl itself.