File: visitor.t

package info (click to toggle)
libcql-parser-perl 1.13-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 316 kB
  • sloc: perl: 2,388; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use strict;
use warnings;
use CQL::Parser;
use CQL::Visitor;
use Test::More tests=>2; 

# test the ability to visit term nodes and convert the dc 
# qualifiers

my $parser = CQL::Parser->new();
my $node = $parser->parse( "(dc.title=foo or bar) and dc.creator=baz" );
is( 
    $node->toCQL(), 
    '((dc.title = foo) or (bar)) and (dc.creator = baz)',
    'toCQL() prior to transformation' 
);

my $visitor = MyVisitor->new();
$visitor->visit($node);

is( 
    $node->toCQL(), 
    '((title = foo) or (bar)) and (creator = baz)',
    'visitor worked' 
);


## test visitor class

package MyVisitor;

use base qw( CQL::Visitor );

sub term {
    my ($self,$node) = @_;
    # remove dc prefix from qualifier
    # bad OO, digging right into object
    # need set methods at some point
    if ( $node->{qualifier} ) {
        $node->{qualifier} =~ s/^dc\.//;
    }
}

1;