summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-07-06 19:21:56 -0500
committerJesse Luehrs <doy@tozt.net>2011-07-06 23:48:55 -0500
commit4a1aaf32fde2658905f84ffb76708d7ffe53480f (patch)
treea80e79bc568be9b8cafeefde4b48cbca005ca983 /lib
parent934895217ebd317f2506e6853d3875d7970ea6aa (diff)
downloadsmartmatch-engine-rjbs-4a1aaf32fde2658905f84ffb76708d7ffe53480f.tar.gz
smartmatch-engine-rjbs-4a1aaf32fde2658905f84ffb76708d7ffe53480f.zip
initial implementation
Diffstat (limited to 'lib')
-rw-r--r--lib/smartmatch.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/smartmatch.pm b/lib/smartmatch.pm
index e69de29..f464d95 100644
--- a/lib/smartmatch.pm
+++ b/lib/smartmatch.pm
@@ -0,0 +1,38 @@
+package smartmatch;
+use strict;
+use warnings;
+# ABSTRACT: pluggable smart matching backends
+
+use parent 'DynaLoader';
+use B::Hooks::OP::Check;
+use B::Hooks::EndOfScope;
+
+sub dl_load_flags { 0x01 }
+
+__PACKAGE__->bootstrap(
+ # we need to be careful not to touch $VERSION at compile time, otherwise
+ # DynaLoader will assume it's set and check against it, which will cause
+ # fail when being run in the checkout without dzil having set the actual
+ # $VERSION
+ exists $smartmatch::{VERSION}
+ ? ${ $smartmatch::{VERSION} } : (),
+);
+
+sub import {
+ my $package = shift;
+ my ($cb) = @_;
+ $cb = $cb->can('match') unless ref($cb);
+
+ $^H ||= 0x020000; # HINT_LOCALIZE_HH
+
+ $package->unimport;
+ $^H{'smartmatch_cb'} = smartmatch::register($cb);
+ on_scope_end { $package->unimport };
+}
+
+sub unimport {
+ return unless exists $^H{'smartmatch_cb'};
+ smartmatch::unregister(delete $^H{'smartmatch_cb'});
+}
+
+1;