summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/smartmatch.pm20
-rw-r--r--smartmatch.xs5
2 files changed, 12 insertions, 13 deletions
diff --git a/lib/smartmatch.pm b/lib/smartmatch.pm
index 0524799..ad3caaa 100644
--- a/lib/smartmatch.pm
+++ b/lib/smartmatch.pm
@@ -57,21 +57,19 @@ my $anon = 1;
sub import {
my $package = shift;
- my ($cb) = @_;
+ my ($engine) = @_;
- my $engine;
-
- if (ref($cb)) {
- $engine = 'smartmatch::engine::__ANON__::' . $anon;
- my $anon_stash = Package::Stash->new($engine);
+ if (ref($engine)) {
+ my $cb = $engine;
+ $engine = '__ANON__::' . $anon++;
+ my $anon_stash = Package::Stash->new("smartmatch::engine::$engine");
$anon_stash->add_symbol('&match' => $cb);
- $anon++;
}
else {
- $engine = "smartmatch::engine::$cb";
- use_package_optimistically($engine);
- die "$engine does not implement a 'match' function"
- unless $engine->can('match');
+ my $package = "smartmatch::engine::$engine";
+ use_package_optimistically($package);
+ die "$package does not implement a 'match' function"
+ unless $package->can('match');
}
register($engine);
diff --git a/smartmatch.xs b/smartmatch.xs
index 49a13a8..28b62cd 100644
--- a/smartmatch.xs
+++ b/smartmatch.xs
@@ -92,8 +92,9 @@ smartmatch_cb(pTHX_ OP *o, void *user_data)
}
#endif
- cb_name = newSVsv(*engine);
- sv_catpv(cb_name, "::match");
+ cb_name = newSVpvs("smartmatch::engine::");
+ sv_catsv(cb_name, *engine);
+ sv_catpvs(cb_name, "::match");
cb_op = newUNOP(OP_RV2CV, 0, newGVOP(OP_GV, 0, gv_fetchsv(cb_name, 0, SVt_PVCV)));
list = newLISTOP(OP_LIST, 0, left, right);