~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Query/OP_ref.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See bottom of file for copyright and license details
 
2
 
 
3
=begin TML
 
4
 
 
5
---+ package Foswiki::Query::OP_ref
 
6
 
 
7
=cut
 
8
 
 
9
package Foswiki::Query::OP_ref;
 
10
use base 'Foswiki::Query::BinaryOP';
 
11
 
 
12
use strict;
 
13
use Error qw( :try );
 
14
 
 
15
sub new {
 
16
    my $class = shift;
 
17
    return $class->SUPER::new( name => '/', prec => 700 );
 
18
}
 
19
 
 
20
sub evaluate {
 
21
    my $this   = shift;
 
22
    my $pnode  = shift;
 
23
    my %domain = @_;
 
24
 
 
25
    my $session = $domain{tom}->session;
 
26
    my $topic   = $domain{tom}->topic;
 
27
 
 
28
    my $a    = $pnode->{params}[0];
 
29
    my $node = $a->evaluate(@_);
 
30
    return undef unless defined $node;
 
31
    if ( ref($node) eq 'HASH' ) {
 
32
        return undef;
 
33
    }
 
34
    if ( !( ref($node) eq 'ARRAY' ) ) {
 
35
        $node = [$node];
 
36
    }
 
37
    my @result;
 
38
    foreach my $v (@$node) {
 
39
 
 
40
        # Has to be relative to the web of the topic we are querying
 
41
        my ( $w, $t ) =
 
42
          $session->normalizeWebTopicName( $session->{webName}, $v );
 
43
        my $result = undef;
 
44
        try {
 
45
            my $submeta = $domain{tom}->getMetaFor( $w, $t );
 
46
            my $b       = $pnode->{params}[1];
 
47
            my $res     = $b->evaluate( tom => $submeta, data => $submeta );
 
48
            if ( ref($res) eq 'ARRAY' ) {
 
49
                push( @result, @$res );
 
50
            }
 
51
            else {
 
52
                push( @result, $res );
 
53
            }
 
54
        }
 
55
        catch Error::Simple with {};
 
56
    }
 
57
    return undef unless scalar(@result);
 
58
    return $result[0] if scalar(@result) == 1;
 
59
    return \@result;
 
60
}
 
61
 
 
62
1;
 
63
 
 
64
__DATA__
 
65
 
 
66
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/, http://Foswiki.org/
 
67
 
 
68
# Copyright (C) 2008-2009 Foswiki Contributors. All Rights Reserved.
 
69
# Foswiki Contributors are listed in the AUTHORS file in the root
 
70
# of this distribution. NOTE: Please extend that file, not this notice.
 
71
#
 
72
# Additional copyrights apply to some or all of the code in this
 
73
# file as follows:
 
74
#
 
75
# Copyright (C) 2005-2007 TWiki Contributors. All Rights Reserved.
 
76
# TWiki Contributors are listed in the AUTHORS file in the root
 
77
# of this distribution. NOTE: Please extend that file, not this notice.
 
78
#
 
79
This program is free software; you can redistribute it and/or
 
80
modify it under the terms of the GNU General Public License
 
81
as published by the Free Software Foundation; either version 2
 
82
of the License, or (at your option) any later version. For
 
83
more details read LICENSE in the root of this distribution.
 
84
 
 
85
This program is distributed in the hope that it will be useful,
 
86
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
87
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
88
 
 
89
As per the GPL, removal of this notice is prohibited.
 
90
 
 
91
Author: Crawford Currie http://c-dot.co.uk