/[cvs]/nfo/perl/libs/Data/Query/Filter/Regexp.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Data/Query/Filter/Regexp.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Tue May 13 07:45:21 2003 UTC (21 years, 2 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +8 -5 lines
now returns report

1 joko 1.1 ## ------------------------------------------------------------------------
2 joko 1.5 ## $Id: Regexp.pm,v 1.4 2003/03/27 15:31:03 joko Exp $
3 joko 1.1 ## ------------------------------------------------------------------------
4 joko 1.2 ## $Log: Regexp.pm,v $
5 joko 1.5 ## Revision 1.4 2003/03/27 15:31:03 joko
6     ## fixes to modules regarding new namespace(s) below Data::Mungle::*
7     ##
8 joko 1.4 ## Revision 1.3 2003/02/20 18:56:41 joko
9     ## renamed modules
10     ##
11 joko 1.3 ## Revision 1.2 2003/02/09 04:53:23 joko
12     ## + object creation done via new mechanism
13     ##
14 joko 1.2 ## Revision 1.1 2002/12/23 04:22:22 joko
15     ## + refactored from Data::Filter
16     ##
17 joko 1.1 ## Revision 1.1 2002/12/22 14:19:17 joko
18     ## + initial check-in
19     ##
20     ## ------------------------------------------------------------------------
21    
22    
23     package Data::Query::Filter::Regexp;
24    
25     use strict;
26     use warnings;
27    
28 joko 1.3 use base qw( DesignPattern::Logger );
29 joko 1.1
30    
31     use Data::Dumper;
32    
33     use Regexp::Group;
34 joko 1.2 use DesignPattern::Object;
35 joko 1.4 use Data::Mungle::Compare::Struct qw( isEmpty );
36 joko 1.1
37     # ------------ common perl object constructor ------------
38     sub new {
39     my $invocant = shift;
40     my $class = ref($invocant) || $invocant;
41     my @args = ();
42     @_ && (@args = @_);
43     #$logger->debug( __PACKAGE__ . "->new( @args )" ); # this is not "common"!
44     my $self = { @_ };
45     bless $self, $class;
46     $self->{caller} = caller;
47    
48     #print Dumper(caller(2));
49     #exit;
50    
51     $self->_init();
52     return $self;
53     }
54    
55     sub _init {
56     my $self = shift;
57    
58     # try to load filter-declaration from configuration scope inside perl-module (yes - it's already abstracted out there!)
59 joko 1.2 $self->{declaration} = DesignPattern::Object->fromPackage($self->{module});
60 joko 1.5 #print Dumper($self->{declaration});
61 joko 1.1
62     # the regexp-object which does the hard work for us ;-)
63     $self->{regexp} = Regexp::Group->new(
64     'data' => \$self->{data}, # reference ...
65     #'data' => $self->{data}, # ... or not?
66     'metadata' => $self->{declaration}->metadata(),
67     'patterns' => $self->{declaration}->patterns(),
68     'coderefs' => $self->{declaration}->coderefs(),
69     'verbose' => 1,
70 joko 1.5 'LOG_VERBOSE' => 0,
71 joko 1.1 );
72    
73     }
74    
75     sub run {
76     my $self = shift;
77     my $steps = shift;
78     my $coderef = shift;
79    
80     #print "cb: $coderef", "\n";
81    
82 joko 1.5 $self->{regexp}->scan($steps, $coderef);
83 joko 1.1
84     # configure tracing
85     # respects additional trace-options passed to _trace-method
86     $self->{TRACE_OPTIONS} = 1;
87     # disables _any_ tracing - even if sub-conditions evaluate to true values
88     $self->{TRACE_DISABLED} = 0;
89    
90     # trace the result
91     # cute: ;-)
92     #$self->trace('matches after Regexp::Group->scan', $self->{regexp}->getMatches(), 1, undef, { tag => '', exit => 0 });
93     #$self->trace('results after Regexp::Group->scan', $self->{regexp}->getResults(), 1, undef, { tag => '', exit => 0 });
94    
95 joko 1.5 return $self->{regexp}->get_report();
96 joko 1.1 }
97    
98     sub index {
99     my $self = shift;
100     my $steps = shift;
101    
102     # configure tracing
103     # respects additional trace-options passed to _trace-method
104     $self->{TRACE_OPTIONS} = 1;
105     # disables _any_ tracing - even if sub-conditions evaluate to true values
106     $self->{TRACE_DISABLED} = 0;
107    
108     # trace the result
109     # cute: ;-)
110     #$self->trace('matches after Regexp::Group->scan', $self->{regexp}->getMatches(), 1, undef, { tag => '', exit => 0 });
111     #$self->trace('results after Regexp::Group->scan', $self->{regexp}->getResults(), 1, undef, { tag => '', exit => 0 });
112    
113     my $result = $self->{regexp}->scan($steps);
114    
115    
116     return $result;
117     }
118    
119     sub continue {
120     my $self = shift;
121     my $scankey = shift;
122     my $result = $self->{regexp}->continue($scankey);
123     }
124    
125     sub getResults {
126     my $self = shift;
127     return $self->{regexp}->{result};
128     }
129    
130     sub getResultCount {
131     my $self = shift;
132     #my $count = ($#{$self->{regexp}->{result}} == -1 ? 0 : $#{$self->{regexp}->{result}});
133     #$count++;
134    
135    
136     my $matches = $self->{regexp}->getMatches();
137     return if isEmpty($matches);
138    
139     my $count = $#{$matches};
140     $count++;
141     return $count;
142     }
143    
144     1;

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed