| 1 | ############################################################################## |
|---|
| 2 | # |
|---|
| 3 | # This library is free software; you can redistribute it and/or |
|---|
| 4 | # modify it under the terms of the GNU Library General Public |
|---|
| 5 | # License as published by the Free Software Foundation; either |
|---|
| 6 | # version 2 of the License, or (at your option) any later version. |
|---|
| 7 | # |
|---|
| 8 | # This library is distributed in the hope that it will be useful, |
|---|
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 11 | # Library General Public License for more details. |
|---|
| 12 | # |
|---|
| 13 | # You should have received a copy of the GNU Library General Public |
|---|
| 14 | # License along with this library; if not, write to the |
|---|
| 15 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 16 | # Boston, MA 02111-1307, USA. |
|---|
| 17 | # |
|---|
| 18 | # Jabber |
|---|
| 19 | # Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/ |
|---|
| 20 | # |
|---|
| 21 | ############################################################################## |
|---|
| 22 | |
|---|
| 23 | package XML::Stream::XPath::Value; |
|---|
| 24 | |
|---|
| 25 | use 5.006_001; |
|---|
| 26 | use strict; |
|---|
| 27 | use vars qw( $VERSION ); |
|---|
| 28 | |
|---|
| 29 | $VERSION = "1.22"; |
|---|
| 30 | |
|---|
| 31 | sub new |
|---|
| 32 | { |
|---|
| 33 | my $proto = shift; |
|---|
| 34 | my $self = { }; |
|---|
| 35 | |
|---|
| 36 | bless($self,$proto); |
|---|
| 37 | |
|---|
| 38 | $self->setList(@_); |
|---|
| 39 | $self->setValues(); |
|---|
| 40 | $self->setAttribs(); |
|---|
| 41 | $self->setValid(0); |
|---|
| 42 | $self->in_context(0); |
|---|
| 43 | |
|---|
| 44 | return $self; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | sub setList |
|---|
| 49 | { |
|---|
| 50 | my $self = shift; |
|---|
| 51 | my (@values) = @_; |
|---|
| 52 | $self->{LIST} = \@values; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | sub getList |
|---|
| 57 | { |
|---|
| 58 | my $self = shift; |
|---|
| 59 | return unless ($#{$self->{LIST}} > -1); |
|---|
| 60 | return @{$self->{LIST}}; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | sub getFirstElem |
|---|
| 65 | { |
|---|
| 66 | my $self = shift; |
|---|
| 67 | return unless ($#{$self->{LIST}} > -1); |
|---|
| 68 | return $self->{LIST}->[0]; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | sub setValues |
|---|
| 73 | { |
|---|
| 74 | my $self = shift; |
|---|
| 75 | my (@values) = @_; |
|---|
| 76 | $self->{VALUES} = \@values; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | sub getValues |
|---|
| 81 | { |
|---|
| 82 | my $self = shift; |
|---|
| 83 | return unless ($#{$self->{VALUES}} > -1); |
|---|
| 84 | return $self->{VALUES}->[0] if !wantarray; |
|---|
| 85 | return @{$self->{VALUES}}; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | sub setAttribs |
|---|
| 90 | { |
|---|
| 91 | my $self = shift; |
|---|
| 92 | my (%attribs) = @_; |
|---|
| 93 | $self->{ATTRIBS} = \%attribs; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | sub getAttribs |
|---|
| 98 | { |
|---|
| 99 | my $self = shift; |
|---|
| 100 | return unless (scalar(keys(%{$self->{ATTRIBS}})) > 0); |
|---|
| 101 | return %{$self->{ATTRIBS}}; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | sub setValid |
|---|
| 106 | { |
|---|
| 107 | my $self = shift; |
|---|
| 108 | my $valid = shift; |
|---|
| 109 | $self->{VALID} = $valid; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | sub check |
|---|
| 114 | { |
|---|
| 115 | my $self = shift; |
|---|
| 116 | return $self->{VALID}; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | sub in_context |
|---|
| 121 | { |
|---|
| 122 | my $self = shift; |
|---|
| 123 | my $in_context = shift; |
|---|
| 124 | |
|---|
| 125 | if (defined($in_context)) |
|---|
| 126 | { |
|---|
| 127 | $self->{INCONTEXT} = $in_context; |
|---|
| 128 | } |
|---|
| 129 | return $self->{INCONTEXT}; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | sub display |
|---|
| 134 | { |
|---|
| 135 | my $self = shift; |
|---|
| 136 | if (0) |
|---|
| 137 | { |
|---|
| 138 | print "VALUE: list(",join(",",@{$self->{LIST}}),")\n"; |
|---|
| 139 | } |
|---|
| 140 | else |
|---|
| 141 | { |
|---|
| 142 | print "VALUE: list(\n"; |
|---|
| 143 | foreach my $elem (@{$self->{LIST}}) |
|---|
| 144 | { |
|---|
| 145 | print "VALUE: ",$elem->GetXML(),"\n"; |
|---|
| 146 | } |
|---|
| 147 | print "VALUE: )\n"; |
|---|
| 148 | } |
|---|
| 149 | print "VALUE: values(",join(",",@{$self->{VALUES}}),")\n"; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | 1; |
|---|
| 153 | |
|---|