⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gofer.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 4 页
字号:
Multiple resultsets are supported only if the driver supports the more_results() method(an exception is made for DBD::Sybase).=head2 Statement activity that also updates dbh attributesSome drivers may update one or more dbh attributes after performing activity ona child sth.  For example, DBD::mysql provides $dbh->{mysql_insertid} in addition to$sth->{mysql_insertid}. Currently mysql_insertid is supported via a hack but amore general mechanism is needed for other drivers to use.=head2 Methods that report an error always return undefWith DBD::Gofer, a method that sets an error always return an undef or empty list.That shouldn't be a problem in practice because the DBI doesn't define anymethods that return meaningful values while also reporting an error.=head2 Subclassing only applies to client-sideThe RootClass and DbTypeSubclass attributes are not passed to the Gofer server.=head1 CAVEATS FOR SPECIFIC METHODS=head2 last_insert_idTo enable use of last_insert_id you need to indicate to DBD::Gofer that you'dlike to use it.  You do that my adding a C<go_last_insert_id_args> attribute tothe do() or prepare() method calls. For example:    $dbh->do($sql, { go_last_insert_id_args => [...] });or    $sth = $dbh->prepare($sql, { go_last_insert_id_args => [...] });The array reference should contains the args that you want passed to thelast_insert_id() method.=head2 execute_for_fetchThe array methods bind_param_array() and execute_array() are supported.When execute_array() is called the data is serialized and executed in a singleround-trip to the Gofer server. This makes it very fast, but requires enoughmemory to store all the serialized data.The execute_for_fetch() method currently isn't optimised, it uses the DBIfallback behaviour of executing each tuple individually.(It could be implemented as a wrapper for execute_array() - patches welcome.)=head1 TRANSPORTSDBD::Gofer doesn't concern itself with transporting requests and responses to and fro.For that it uses special Gofer transport modules.Gofer transport modules usually come in pairs: one for the 'client' DBD::Goferdriver to use and one for the remote 'server' end. They have very similar names:    DBD::Gofer::Transport::<foo>    DBI::Gofer::Transport::<foo>Sometimes the transports on the DBD and DBI sides may have different names. Forexample DBD::Gofer::Transport::http is typically used with DBI::Gofer::Transport::mod_perl(DBD::Gofer::Transport::http and DBI::Gofer::Transport::mod_perl modules arepart of the GoferTransport-http distribution).=head2 Bundled TransportsSeveral transport modules are provided with DBD::Gofer:=head3 nullThe null transport is the simplest of them all. It doesn't actually transport the request anywhere.It just serializes (freezes) the request into a string, then thaws it back intoa data structure before passing it to DBI::Gofer::Execute to execute. The samefreeze and thaw is applied to the results.The null transport is the best way to test if your application will work with Gofer.Just set the DBI_AUTOPROXY environment variable to "C<dbi:Gofer:transport=null;policy=pedantic>"(see L</Using DBI_AUTOPROXY> below) and run your application, or ideally its test suite, as usual.It doesn't take any parameters.=head3 pipeoneThe pipeone transport launches a subprocess for each request. It passes in therequest and reads the response.The fact that a new subprocess is started for each request ensures that theserver side is truly stateless. While this does make the transport I<very> slow,it is useful as a way to test that your application doesn't depend onper-connection state, such as temporary tables, persisting between requests.It's also useful both as a proof of concept and as a base class for the streamdriver.=head3 streamThe stream driver also launches a subprocess and writes requests and readsresponses, like the pipeone transport.  In this case, however, the subprocessis expected to handle more that one request. (Though it will be automiticallyrestarted if it exits.)This is the first transport that is truly useful because it can launch thesubprocess on a remote machine using C<ssh>. This means you can now use DBD::Goferto easily access any databases that's accessible from any system you can login to.You also get all the benefits of ssh, including encryption and optional compression.See L</Using DBI_AUTOPROXY> below for an example.=head2 Other TransportsImplementing a Gofer transport is I<very> simple, and more transports are very welcome.Just take a look at any existing transports that are similar to your needs.=head3 httpSee the GoferTransport-http distribution on CPAN: http://search.cpan.org/dist/GoferTransport-http/=head3 GearmanI know Ask Bj鴕n Hansen has implemented a transport for the C<gearman> distributedjob system, though it's not on CPAN at the time of writing this.=head1 CONNECTINGSimply prefix your existing DSN with "C<dbi:Gofer:transport=$transport;dsn=>"where $transport is the name of the Gofer transport you want to use (see L</TRANSPORTS>).The C<transport> and C<dsn> attributes must be specified and the C<dsn> attributes must be last.Other attributes can be specified in the DSN to configure DBD::Gofer and/or theGofer transport module being used. The main attributes after C<transport>, areC<url> and C<policy>. These and other attributes are described below.=head2 Using DBI_AUTOPROXYThe simplest way to try out DBD::Gofer is to set the DBI_AUTOPROXY environment variable.In this case you don't include the C<dsn=> part. For example:    export DBI_AUTOPROXY="dbi:Gofer:transport=null"or, for a more useful example, try:    export DBI_AUTOPROXY="dbi:Gofer:transport=stream;url=ssh:user@example.com"=head2 Connection AttributesThese attributes can be specified in the DSN. They can also be passed in the\%attr parameter of the DBI connect method by adding a "C<go_>" prefix to the name.=head3 transportSpecifies the Gofer transport class to use. Required. See L</TRANSPORTS> above.If the value does not include C<::> then "C<DBD::Gofer::Transport::>" is prefixed.The transport object can be accessed via $h->{go_transport}.=head3 dsnSpecifies the DSN for the remote side to connect to. Required, and must be last.=head3 urlUsed to tell the transport where to connect to. The exact form of the value depends on the transport used.=head3 policySpecifies the policy to use. See L</CONFIGURING BEHAVIOUR POLICY>.If the value does not include C<::> then "C<DBD::Gofer::Policy>" is prefixed.The policy object can be accessed via $h->{go_policy}.=head3 timeoutSpecifies a timeout, in seconds, to use when waiting for responses from the server side.=head3 retry_limitSpecifies the number of times a failed request will be retried. Default is 0.=head3 retry_hookSpecifies a code reference to be called to decide if a failed request should be retried.The code reference is called like this:  $transport = $h->{go_transport};  $retry = $transport->go_retry_hook->($request, $response, $transport);If it returns true then the request will be retried, upto the C<retry_limit>.If it returns a false but defined value then the request will not be retried.If it returns undef then the default behaviour will be used, as if C<retry_hook>had not been specified.The default behaviour is to retry requests where $request->is_idempotent is true,or the error message matches C</induced by DBI_GOFER_RANDOM/>.    =head3 cacheSpecifies that client-side caching should be performed.  The value is the nameof a cache class to use.Any class implementing get($key) and set($key, $value) methods can be used.That includes a great many powerful caching classes on CPAN, including theCache and Cache::Cache distributions.You can use "C<cache=1>" is a shortcut for "C<cache=DBI::Util::CacheMemory>".See L<DBI::Util::CacheMemory> for a description of this simple fast default cache.The cache object can be accessed via $h->go_cache. For example:    $dbh->go_cache->clear; # free up memory being used by the cacheThe cache keys are the frozen (serialized) requests, and the values are thefrozen responses.The default behaviour is to only use the cache for requests where$request->is_idempotent is true (i.e., the dbh has the ReadOnly attribute setor the SQL statement is obviously a SELECT without a FOR UPDATE clause.)For even more control you can use the C<go_cache> attribute to pass in aninstanciated cache object. Individual methods, including prepare(), can alsospecify alternative caches via the C<go_cache> attribute. For example, tospecify no caching for a particular query, you could use    $sth = $dbh->prepare( $sql, { go_cache => 0 } );This can be used to implement different caching policies for different statements.It's interesting to note that DBD::Gofer can be used to add client-side cachingto any (gofer compatible) application, with no code changes and no need for agofer server.  Just set the DBI_AUTOPROXY environment variable like this:    DBI_AUTOPROXY='dbi:Gofer:transport=null;cache=1'=head1 CONFIGURING BEHAVIOUR POLICYDBD::Gofer supports a 'policy' mechanism that allows you to fine-tune the number of round-trips to the Gofer server.The policies are grouped into classes (which may be subclassed) and referenced by the name of the class.The L<DBD::Gofer::Policy::Base> class is the base class for all the policypackages and describes all the available policies.Three policy packages are supplied with DBD::Gofer:L<DBD::Gofer::Policy::pedantic> is most 'transparent' but slowest because itmakes more  round-trips to the Gofer server.L<DBD::Gofer::Policy::classic> is a reasonable compromise - it's the default policy.L<DBD::Gofer::Policy::rush> is fastest, but may require code changes in your applications.Generally the default C<classic> policy is fine. When first testing an existingapplication with Gofer it is a good idea to start with the C<pedantic> policyfirst and then switch to C<classic> or a custom policy, for final testing.=head1 AUTHORTim Bunce, L<http://www.tim.bunce.name>=head1 LICENCE AND COPYRIGHTCopyright (c) 2007, Tim Bunce, Ireland. All rights reserved.This module is free software; you can redistribute it and/ormodify it under the same terms as Perl itself. See L<perlartistic>.=head1 ACKNOWLEDGEMENTSThe development of DBD::Gofer and related modules was sponsored byShopzilla.com (L<http://Shopzilla.com>), where I currently work.=head1 SEE ALSOL<DBI::Gofer::Request>, L<DBI::Gofer::Response>, L<DBI::Gofer::Execute>.L<DBI::Gofer::Transport::Base>, L<DBD::Gofer::Policy::Base>.L<DBI>=head1 Caveats for specific driversThis section aims to record issues to be aware of when using Gofer with specific drivers.It usually only documents issues that are not natural consequences of the limitationsof the Gofer approach - as documented avove.=head1 TODOThis is just a random brain dump... (There's more in the source of the Changes file, not the pod)Document policy mechanismAdd mechanism for transports to list config params and for Gofer to apply any that match (and warn if any left over?)Driver-private sth attributes - set via prepare() - change DBI specadd hooks into transport base class for checking & updating a result set cache   ie via a standard cache interface such as:   http://search.cpan.org/~robm/Cache-FastMmap/FastMmap.pm   http://search.cpan.org/~bradfitz/Cache-Memcached/lib/Cache/Memcached.pm   http://search.cpan.org/~dclinton/Cache-Cache/   http://search.cpan.org/~cleishman/Cache/Also caching instructions could be passed through the httpd transport layerin such a way that appropriate http cache headers are added to the resultsso that web caches (squid etc) could be used to implement the caching.(MUST require the use of GET rather than POST requests.)Rework handling of installed_methods to not piggback on dbh_attributes?Perhaps support transactions for transports where it's possible (ie null and stream)?Would make stream transport (ie ssh) more useful to more people.Make sth_result_attr more like dbh_attributes (using '*' etc)Add @val = FETCH_many(@names) to DBI in C and use in Gofer/Execute?Implement _new_sth in C.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -