Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

refactor load_plugin. write document for load_plugin. #71

Merged
merged 1 commit into from

2 participants

Atsushi Kato Atsushi Kobayashi
Atsushi Kato

load_plugin のりファクタと、ドキュメント書いてみました。
こんなんでどうでしょう?

Atsushi Kobayashi nekokak merged commit 6087a46 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 4, 2012
  1. Atsushi Kato
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 8 deletions.
  1. +16 −8 lib/Teng.pm
24 lib/Teng.pm
View
@@ -33,14 +33,10 @@ sub load_plugin {
$class = ref($class) if ref($class);
- my $alias = delete $opt->{alias};
+ my $alias = delete $opt->{alias} || {};
no strict 'refs';
- for my $meth ( @{"${pkg}::EXPORT"} ) {
- my $dest_meth =
- ( $alias && $alias->{$meth} )
- ? $alias->{$meth}
- : $meth;
- *{"${class}::${dest_meth}"} = $pkg->can($meth);
+ for my $method ( @{"${pkg}::EXPORT"} ){
+ *{$class . '::' . ($alias->{$method} || $method)} = $pkg->can($method);
}
$pkg->init($class, $opt) if $pkg->can('init');
@@ -999,7 +995,19 @@ set row object creation mode.
=item $teng->load_plugin();
-load Teng::Plugin's
+ $teng->load_plugin($plugin_class, $options);
+
+This imports plugin class's methods to C<$teng> class
+and it calls $plugin_class's init method if it has.
+
+ $plugin_class->init($teng, $options);
+
+If you want to change imported method name, use C<alias> option.
+for example:
+
+ YourDB->load_plugin('BulkInsert', { alias => { bulk_insert => 'isnert_bulk' } });
+
+BulkInsert's "bulk_insert" method is imported as "insert_bulk".
=item $teng->handle_error
Something went wrong with that request. Please try again.