| Data-Rx-Type-PCRE documentation | Contained in the Data-Rx-Type-PCRE distribution. |
Data::Rx::Type::PCRE - PCRE string checking for Rx (experimental)
version 0.002
use Data::Rx;
use Data::Rx::Type::PCRE;
my $rx = Data::Rx->new({
type_plugins => [ 'Data::Rx::Type::PCRE' ]
});
my $ph_number = $rx->make_schema({
type => 'tag:rjbs.manxome.org,2008-10-04:rx/pcre/str',
regex => q/\A867-[5309]{4}\z/,
});
This provides a new type, currently known as
tag:rjbs.manxome.org,2008-10-04:rx/pcre/str, which checks strings against
the Perl-compatible regular expression library. Note! This uses PCRE, not
Perl's regular expressions. There are differences, but very few.
Schema definitions must have a regex parameter, which provides the regular
expression as a string. They may also have a flags parameter, which
provides regular expression flags to be passed to the (?i-i) style flag
modifier.
Ricardo SIGNES <rjbs@cpan.org>
This software is copyright (c) 2008 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under the same terms as perl itself.
This plugin is still pretty experimental. When it's less so, it may get a new type URI. Its interface may change between now and then.
| Data-Rx-Type-PCRE documentation | Contained in the Data-Rx-Type-PCRE distribution. |
use strict; use warnings; use 5.010; package Data::Rx::Type::PCRE; our $VERSION = '0.002'; # ABSTRACT: PCRE string checking for Rx (experimental) use Carp (); sub type_uri { 'tag:rjbs.manxome.org,2008-10-04:rx/pcre/str' } sub new_checker { my ($class, $arg, $rx) = @_; my $regex = $arg->{regex}; my $flags = $arg->{flags} // ''; Carp::croak("no regex supplied for $class type") unless defined $regex; my $regex_str = (length $flags) ? "(?$flags)$regex" : $regex; my $re = do { use re::engine::PCRE; qr{$regex_str}; }; my $self = { re => $re }; bless $self => $class; return $self; } sub check { my ($self, $value) = @_; return unless $value =~ $self->{re}; return 1; } 1; __END__