📄 bk_new_perl.html
字号:
<html><head><title>BabelKit Perl Handle Creation</title><link rel="STYLESHEET" type="text/css" href="main.css"></head><!-- Copyright (C) 2003 John Gorman <jgorman@webbysoft.com> http://www.webbysoft.com/babelkit--><body bgcolor="#F0FFFF" text="#000000" link="#873852" vlink="#873852" alink="#B52E2E"><center><table width="600"><tr><td><div align="right">[<a href="bk_quick_perl.html">Perl API</a>][<a href="index.html">Index</a>][<a href="bk_read.html">Code Descriptions</a>]</div><center><h2><a href="http://www.webbysoft.com/babelkit">BabelKit</a>Perl Handle Creation</h2></center>How to create a new Perl BabelKit access handle.<h4>new DBIx::BabelKit()</h4><pre>use DBIx::BabelKit;$babelkit = new DBIx::BabelKit($dbh, table => 'bk_code', getparam => \&get_scalar, getparams => \&get_list ):</pre><p>The new BabelKit() method returns a new BabelKit handleobject.<p>$dbh is an open DBI connection handle. If you planto update the code table set it up to autocommit.<p>The optional 'table' parameter can be used to specifywhich of several physical code tables to use. The default is'bk_code'.<h4>Getting Form Variables in Perl</h4><p>The 'getparam' and 'getparams' function referencestell BabelKit where to look for incoming form valuesfor the <a href="bk_select.html">HTML Select Methods</a>.If this seems complicated you can simply pass in yourown values to those methods using the 'value' parameter.<p>Here is an example showing how BabelKit can get theincoming form values using the popular CGI module:<pre>use DBI;use CGI;use DBIx::BabelKit;# Database connection. Set these.my $dbconnect = "DBI:mysql:webbysoft:localhost";my $dbusername = "webbysoft";my $dbpassword = "124c41";my $dbh = DBI->connect($dbconnect, $dbusername, $dbpassword) or die "connecting : $DBI::errstr\n";my $cgi = new CGI;my $babelkit = new DBIx::BabelKit($dbh, getparam => sub { $cgi->param(shift) }, getparams => sub { $cgi->param((shift).'[]') } );</pre><p>Notice the 'my $cgi' variable holding a reference to the CGIobject. The anonymous sub definitions will use thatreference when they are called by BabelKit. You can alsopass in a reference to a regular named function asillustrated below.<p>The 'getparam' sub will be called in a scalar context to returnsingle valued HTML form selections. The name of the form variableto return is passed in as the first argument. It should returna scalar value such as a string.<p>The 'getparams' sub will be called in a list context to returnmultivalued HTML form selections. The name of the form variableto return is passed in as the first argument *without* the '[]'at the end of the name. Append '[]' to the name if yourparameter interface uses that convention.<p>The 'getparams' sub can return a list, a reference to a list,a scalar, or a reference to a hash. If you return a referenceto a hash, the keys are the selections, and the valuesare true like this:<pre>sub singleparam { my $var_name = shift; # Ignored for simplicity. return 'friday'; # Look in POST or GET.}sub multiparam { my $var_name = shift; # Ignored for simplicity. my $values = { # Look in POST or GET. 'new_york' => 1, 'san_francisco' => 1, 'halifax => 1 }; return $values; # Return a hash ref.}my $babelkit = new DBIx::BabelKit($dbh, getparam => \&singleparam, getparams => \&multiparam );</pre><p><div align="right">[<a href="bk_quick_perl.html">Perl API</a>][<a href="index.html">Index</a>][<a href="bk_read.html">Code Descriptions</a>]</div></td></tr></table></center></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -