| 1 | package re::engine::TRE; | ||
| 2 | # ABSTRACT: TRE regular expression engine | ||
| 3 | |||
| 4 | |||
| 5 | use strict; | ||
| 6 | use utf8; | ||
| 7 | use warnings qw(all); | ||
| 8 | |||
| 9 | use 5.010000; | ||
| 10 | use Scalar::Util qw(looks_like_number); | ||
| 11 | use XSLoader (); | ||
| 12 | |||
| 13 | # All engines should subclass the core Regexp package | ||
| 14 | our @ISA = 'Regexp'; | ||
| 15 | |||
| 16 | BEGIN { | ||
| 17 | our $VERSION = '0.09'; # VERSION | ||
| 18 | XSLoader::load __PACKAGE__, $VERSION; | ||
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | sub import { | ||
| 23 | shift; | ||
| 24 | |||
| 25 | $^H{regcomp} = ENGINE; | ||
| 26 | |||
| 27 | if (@_) { | ||
| 28 | my %args = @_; | ||
| 29 | $^H{__PACKAGE__ . '::' . $_} = | ||
| 30 | $args{$_} < 0 | ||
| 31 | ? 0x7fff | ||
| 32 | : int($args{$_}) | ||
| 33 | for grep { | ||
| 34 | exists $args{$_} | ||
| 35 | and looks_like_number($args{$_}) | ||
| 36 | } qw( | ||
| 37 | cost_ins | ||
| 38 | cost_del | ||
| 39 | cost_subst | ||
| 40 | max_cost | ||
| 41 | max_ins | ||
| 42 | max_del | ||
| 43 | max_subst | ||
| 44 | max_err | ||
| 45 | ); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | sub unimport { | ||
| 50 | delete $^H{regcomp} | ||
| 51 | if $^H{regcomp} == ENGINE; | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; | ||
| 55 | |||
| 56 | __END__ |