DBIx::POS::Template

Доброго всем

¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !

VERSION

0.067

NAME

DBIx::POS::Template - is a fork of DBIx::POS. Define a dictionary of SQL statements in a POD dialect (POS) plus expand template sql with embedded Perl using Text::Template.

SYNOPSIS

  use DBIx::POS::Template;

  # separate object
  my $pos = DBIx::POS::Template->new(__FILE__, ...);
  # or singleton DBIx::POS::Template->instance($file, ...);
  
  my $sql = $pos->{test1}->template(where => "bar = ?");
  # or $pos->template('test1', where => "bar = ?")
  
  =pod

  =name test1

  =desc test the DBIx::POS::Template module

  =param
  
    # Some arbitrary parameters as perl code (eval)
    {
        cache=>1, # will be prepare_cached
    }

  =sql

    select * from foo
    {% $where %}
    ;

  =cut

Or:

  package POS::Foo;
  use DBIx::POS::Template;
  use Hash::Merge qw(merge);
  
  my $default = {foo=>'bar',};
  
  sub new {
    my $proto = shift;
    DBIx::POS::Template->new(__FILE__, template => merge({@_}, $default));
    # or DBIx::POS::Template->instance(...
  }

DESCRIPTION

DBIx::POS::Template is subclass Pod::Parser to define a POD dialect for writing a SQL dictionary(s) with templating.

By separating the SQL code from its normal context of execution, it encourages you to do other things with it---for instance, it is easy to create a script that can do performance testing of certain SQL statements in isolation, or to create generic command-line wrapper around your SQL statements.

By giving a framework for documenting the SQL, it encourages documentation of the intent and/or implementation of the SQL code. It also provides all of that information in a format from which other documentation could be generated---say, a chunk of DocBook for incorporation into a guide to programming the application.

This class whould work as separate objects per pod-file or as singleton for all processed files with one dictionary of them.

METHODS

new($file, <options>)

Create separate object and process $file POS with options names:

  • TT | tt

    Optional hashref will passing to Text::Template->new() for each parsed statement. By default only defined the key:

      ..., TT => {DELIMITERS => ['{%', '%}'],},

    For instance this hashref will be merged with previous instance invokes.

  • template

      ..., template => {foo=>1,},

    Optional hashref of default values for each statement template. For instance this hashref will be merged with previous instance invokes.

instance($file, <options>)

Return singleton dictionary object, parsed $file keys will collapse/override with previous instances files. Same options as new. tt and template options merge with previous options of instance invokes.

template($key, var1 => ..., var2 => ...)

Fill in dictionary sql with variables by Text::Template#HASH. Other syntax:

    $pos->{$key}->template(var1 => ..., var2 => ...)

SEE ALSO

Pod::Parser

DBIx::POS

Text::Template

DBIx::POS::Sth

AUTHOR

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

BUGS / CONTRIBUTING

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

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.