.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "DBIx::Custom::SQL::Template 3" .TH DBIx::Custom::SQL::Template 3 "2009-11-16" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" DBIx::Custom::SQL::Template \- Custamizable SQL Template for DBIx::Custom .SH "VERSION" .IX Header "VERSION" Version 0.0101 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& my $sql_tmpl = DBIx::Custom::SQL::Template->new; .Ve .PP .Vb 2 \& my $tmpl = "select from table {= k1} && {<> k2} || {like k3}"; \& my $param = {k1 => 1, k2 => 2, k3 => 3}; .Ve .PP .Vb 1 \& my $query = $sql_template->create_query($tmpl); .Ve .PP .Vb 8 \& # Using query from DBIx::Custom \& use DBIx::Custom; \& my $dbi = DBI->new( \& data_source => $data_source, \& user => $user, \& password => $password, \& dbi_options => {PrintError => 0, RaiseError => 1} \& ); .Ve .PP .Vb 2 \& $query = $dbi->create_query($tmpl); # This is SQL::Template create_query \& $dbi->query($query, $param); .Ve .SH "CLASS-OBJECT ACCESSORS" .IX Header "CLASS-OBJECT ACCESSORS" Class-Object accessor is used from both object and class .PP .Vb 2 \& $class->$accessor # call from class \& $self->$accessor # call form object .Ve .Sh "tag_processors" .IX Subsection "tag_processors" .Vb 3 \& # Set and get \& $self = $sql_tmpl->tag_processors($tag_processors); \& $tag_processors = $sql_tmpl->tag_processors; .Ve .PP .Vb 5 \& # Sample \& $sql_tmpl->tag_processors( \& '?' => \e&expand_question, \& '=' => \e&expand_equel \& ); .Ve .PP You can use add_tag_processor to add tag processor .Sh "tag_start" .IX Subsection "tag_start" .Vb 3 \& # Set and get \& $self = $sql_tmpl->tag_start($tag_start); \& $tag_start = $sql_tmpl->tag_start; .Ve .PP .Vb 2 \& # Sample \& $sql_tmpl->tag_start('{'); .Ve .PP Default is '{' .Sh "tag_end" .IX Subsection "tag_end" .Vb 3 \& # Set and get \& $self = $sql_tmpl->tag_start($tag_end); \& $tag_end = $sql_tmpl->tag_start; .Ve .PP .Vb 2 \& # Sample \& $sql_tmpl->tag_start('}'); .Ve .PP Default is '}' .Sh "tag_syntax" .IX Subsection "tag_syntax" .Vb 3 \& # Set and get \& $self = $sql_tmpl->tag_syntax($tag_syntax); \& $tag_syntax = $sql_tmpl->tag_syntax; .Ve .PP .Vb 7 \& # Sample \& $sql_tmpl->tag_syntax( \& "[Tag] [Expand]\en" . \& "{? name} ?\en" . \& "{= name} name = ?\en" . \& "{<> name} name <> ?\en" \& ); .Ve .SH "METHODS" .IX Header "METHODS" .Sh "create_query" .IX Subsection "create_query" .Vb 2 \& # Create SQL form SQL template \& $query = $sql_tmpl->create_query($tmpl); .Ve .PP .Vb 3 \& # Sample \& $query = $sql_tmpl->create_sql( \& "select * from table where {= title} && {like author} || {<= price}") .Ve .PP .Vb 3 \& # Result \& $qeury->{sql} : "select * from table where title = ? && author like ? price <= ?;" \& $query->{key_infos} : [['title'], ['author'], ['price']] .Ve .PP .Vb 5 \& # Sample2 (with table name) \& ($sql, @bind_values) = $sql_tmpl->create_sql( \& "select * from table where {= table.title} && {like table.author}", \& {table => {title => 'Perl', author => '%Taro%'}} \& ) .Ve .PP .Vb 4 \& # Result2 \& $query->{sql} : "select * from table where table.title = ? && table.title like ?;" \& $query->{key_infos} :[ [['table.title'],['table', 'title']], \& [['table.author'],['table', 'author']] ] .Ve .PP This method create query using by DBIx::Custom. query is two infomation .PP .Vb 2 \& 1.sql : SQL \& 2.key_infos : Parameter access key information .Ve .Sh "add_tag_processor" .IX Subsection "add_tag_processor" Add tag processor .PP .Vb 2 \& # Add \& $self = $sql_tmpl->add_tag_processor($tag_processor); .Ve .PP .Vb 4 \& # Sample \& $sql_tmpl->add_tag_processor( \& '?' => sub { \& my ($tag_name, $tag_args) = @_; .Ve .PP .Vb 2 \& my $key1 = $tag_args->[0]; \& my $key2 = $tag_args->[1]; .Ve .PP .Vb 1 \& my $key_infos = []; .Ve .PP .Vb 1 \& # Expand tag and create key informations .Ve .PP .Vb 4 \& # Return expand tags and key informations \& return ($expand, $key_infos); \& } \& ); .Ve .PP Tag processor recieve 2 argument .PP .Vb 2 \& 1. Tag name (?, =, <>, or etc) \& 2. Tag arguments (arg1 and arg2 in {tag_name arg1 arg2}) .Ve .PP Tag processor return 2 value .PP .Vb 2 \& 1. Expanded Tag (For exsample, '{= title}' is expanded to 'title = ?') \& 2. Key infomations .Ve .PP You must be return expanded tag and key infomations. .PP Key information is a little complex. so I will explan this in future. .PP If you want to know more, Please see DBIx::Custom::SQL::Template source code. .Sh "clone" .IX Subsection "clone" .Vb 2 \& # Clone DBIx::Custom::SQL::Template object \& $clone = $self->clone; .Ve .SH "Available Tags" .IX Header "Available Tags" .Vb 5 \& # Available Tags \& [tag] [expand] \& {? name} ? \& {= name} name = ? \& {<> name} name <> ? .Ve .PP .Vb 4 \& {< name} name < ? \& {> name} name > ? \& {>= name} name >= ? \& {<= name} name <= ? .Ve .PP .Vb 2 \& {like name} name like ? \& {in name} name in [?, ?, ..] .Ve .PP .Vb 2 \& {insert} (key1, key2, key3) values (?, ?, ?) \& {update} set key1 = ?, key2 = ?, key3 = ? .Ve .PP .Vb 6 \& # Sample1 \& $query = $sql_tmpl->create_sql( \& "insert into table {insert key1 key2}" \& ); \& # Result1 \& $sql : "insert into table (key1, key2) values (?, ?)" .Ve .PP .Vb 4 \& # Sample2 \& $query = $sql_tmpl->create_sql( \& "update table {update key1 key2} where {= key3}" \& ); .Ve .PP .Vb 2 \& # Result2 \& $query->{sql} : "update table set key1 = ?, key2 = ? where key3 = ?;" .Ve .SH "AUTHOR" .IX Header "AUTHOR" Yuki Kimoto, \f(CW\*(C`\*(C'\fR .PP Github .PP Please let know me bag if you find Please request me if you want to do something .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2009 Yuki Kimoto, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.