| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package smartmatch; | 
| 2 |  |  |  |  |  |  | BEGIN { | 
| 3 | 4 |  |  | 4 |  | 189141 | $smartmatch::AUTHORITY = 'cpan:DOY'; | 
| 4 |  |  |  |  |  |  | } | 
| 5 |  |  |  |  |  |  | { | 
| 6 |  |  |  |  |  |  | $smartmatch::VERSION = '0.05'; # TRIAL | 
| 7 |  |  |  |  |  |  | } | 
| 8 | 4 |  |  | 4 |  | 38 | use strict; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 145 |  | 
| 9 | 4 |  |  | 4 |  | 29 | use warnings; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 140 |  | 
| 10 | 4 |  |  | 4 |  | 106 | use 5.010; | 
|  | 4 |  |  |  |  | 13 |  | 
|  | 4 |  |  |  |  | 194 |  | 
| 11 |  |  |  |  |  |  | # ABSTRACT: pluggable smart matching backends | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 4 |  |  | 4 |  | 3961 | use parent 'DynaLoader'; | 
|  | 4 |  |  |  |  | 1524 |  | 
|  | 4 |  |  |  |  | 24 |  | 
| 14 | 4 |  |  | 4 |  | 4054 | use B::Hooks::OP::Check; | 
|  | 4 |  |  |  |  | 22691 |  | 
|  | 4 |  |  |  |  | 29081 |  | 
| 15 | 4 |  |  | 4 |  | 4731 | use Module::Runtime 'use_package_optimistically'; | 
|  | 4 |  |  |  |  | 31374 |  | 
|  | 4 |  |  |  |  | 45 |  | 
| 16 | 4 |  |  | 4 |  | 14720 | use Package::Stash; | 
|  | 4 |  |  |  |  | 64580 |  | 
|  | 4 |  |  |  |  | 20179 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 4 |  |  | 4 | 1 | 1129 | sub dl_load_flags { 0x01 } | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | __PACKAGE__->bootstrap( | 
| 21 |  |  |  |  |  |  | # we need to be careful not to touch $VERSION at compile time, otherwise | 
| 22 |  |  |  |  |  |  | # DynaLoader will assume it's set and check against it, which will cause | 
| 23 |  |  |  |  |  |  | # fail when being run in the checkout without dzil having set the actual | 
| 24 |  |  |  |  |  |  | # $VERSION | 
| 25 |  |  |  |  |  |  | exists $smartmatch::{VERSION} | 
| 26 |  |  |  |  |  |  | ? ${ $smartmatch::{VERSION} } : (), | 
| 27 |  |  |  |  |  |  | ); | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | my $anon = 1; | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub import { | 
| 33 | 17 |  |  | 17 |  | 175 | my $package = shift; | 
| 34 | 17 |  |  |  |  | 34 | my ($engine) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 17 | 100 |  |  |  | 54 | if (ref($engine)) { | 
| 37 | 12 |  |  |  |  | 20 | my $cb = $engine; | 
| 38 | 12 |  |  |  |  | 33 | $engine = '__ANON__::' . $anon++; | 
| 39 | 12 |  |  |  |  | 187 | my $anon_stash = Package::Stash->new("smartmatch::engine::$engine"); | 
| 40 | 12 |  |  |  |  | 257 | $anon_stash->add_symbol('&match' => $cb); | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | else { | 
| 43 | 5 |  |  |  |  | 17 | my $package = "smartmatch::engine::$engine"; | 
| 44 | 5 |  |  |  |  | 34 | use_package_optimistically($package); | 
| 45 | 5 | 50 |  |  |  | 1964 | die "$package does not implement a 'match' function" | 
| 46 |  |  |  |  |  |  | unless $package->can('match'); | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 17 |  |  |  |  | 20486 | $^H{'smartmatch/engine'} = $engine; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub unimport { | 
| 53 | 0 |  |  | 0 |  | 0 | delete $^H{'smartmatch/engine'}; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub callback_at_level { | 
| 58 | 4 |  |  | 4 | 1 | 3884 | my ($level) = @_; | 
| 59 | 4 |  |  |  |  | 10 | $level++; | 
| 60 | 4 |  |  |  |  | 32 | my $hh = (caller($level))[10]; | 
| 61 | 4 | 50 |  |  |  | 18 | my $engine = $hh ? $hh->{'smartmatch/engine'} : undef; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 4 |  |  |  |  | 6 | my $recurse; | 
| 64 | 4 | 50 |  |  |  | 9 | if ($engine) { | 
| 65 | 4 |  |  | 1 |  | 345 | $recurse = eval <<"RECURSE"; | 
|  | 1 |  |  | 1 |  | 9 |  | 
|  | 1 |  |  | 1 |  | 2 |  | 
|  | 1 |  |  | 1 |  | 7 |  | 
|  | 1 |  |  |  |  | 6 |  | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 26 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 6 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 66 |  |  |  |  |  |  | use smartmatch '$engine'; | 
| 67 |  |  |  |  |  |  | sub { \$_[0] ~~ \$_[1] } | 
| 68 |  |  |  |  |  |  | RECURSE | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  | else { | 
| 71 | 0 |  |  | 0 |  | 0 | $recurse = sub { $_[0] ~~ $_[1] }; | 
|  | 0 |  |  |  |  | 0 |  | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 4 |  |  |  |  | 17 | return $recurse; | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | 1; | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | __END__ |