String/Regex.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« String/Random.pm ↑ Summary String/Rot13.pm »
1 #
2 # $Id$
3 #
4 # string::regex Brik
5 #
6 package Metabrik::String::Regex;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable encode decode) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 },
20 attributes_default => {
21 },
22 commands => {
23 encode => [ qw($regex|$regex_list) ],
24 },
25 require_modules => {
26 'Regexp::Assemble' => [ ],
27 },
28 };
29 }
30  
31 sub encode {
32 my $self = shift;
33 my ($regex) = @_;
34  
35 $self->brik_help_run_undef_arg('encode', $regex) or return;
36  
37 my $ra = Regexp::Assemble->new
38 or return $self->log->error("encode: Regexp::Assemble new failed");
39  
40 if (ref($regex)) {
41 for my $this (@$regex) {
42 $ra->add($this);
43 }
44 }
45 elsif (! ref($regex)) {
46 $ra->add($regex);
47 }
48  
49 my $encoded;
50 eval {
51 $encoded = $ra->as_string;
52 };
53 if ($@) {
54 chomp($@);
55 return $self->log->error("encode: assembling failed [$@]");
56 }
57  
58 return $encoded;
59 }
60  
61 1;
62  
63 __END__
« String/Random.pm ↑ Summary String/Rot13.pm »