Created
July 4, 2012 10:24
-
-
Save ktat/3046579 to your computer and use it in GitHub Desktop.
Teng alias patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Teng.pm b/lib/Teng.pm | |
index de2f878..a2b3207 100644 | |
--- a/lib/Teng.pm | |
+++ b/lib/Teng.pm | |
@@ -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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment