source: trunk/gsdl/perllib/cpan/XML/XPath/Boolean.pm@ 7909

Last change on this file since 7909 was 7909, checked in by mdewsnip, 20 years ago

CPAN module for processing XPath expressions.

  • Property svn:keywords set to Author Date Id Revision
File size: 1.1 KB
Line 
1# $Id: Boolean.pm 7909 2004-08-06 05:11:55Z mdewsnip $
2
3package XML::XPath::Boolean;
4use XML::XPath::Number;
5use XML::XPath::Literal;
6use strict;
7
8use overload
9 '""' => \&value,
10 '<=>' => \&cmp;
11
12sub True {
13 my $class = shift;
14 my $val = 1;
15 bless \$val, $class;
16}
17
18sub False {
19 my $class = shift;
20 my $val = 0;
21 bless \$val, $class;
22}
23
24sub value {
25 my $self = shift;
26 $$self;
27}
28
29sub cmp {
30 my $self = shift;
31 my ($other, $swap) = @_;
32 if ($swap) {
33 return $other <=> $$self;
34 }
35 return $$self <=> $other;
36}
37
38sub to_number { XML::XPath::Number->new($_[0]->value); }
39sub to_boolean { $_[0]; }
40sub to_literal { XML::XPath::Literal->new($_[0]->value ? "true" : "false"); }
41
42sub string_value { return $_[0]->to_literal->value; }
43
441;
45__END__
46
47=head1 NAME
48
49XML::XPath::Boolean - Boolean true/false values
50
51=head1 DESCRIPTION
52
53XML::XPath::Boolean objects implement simple boolean true/false objects.
54
55=head1 API
56
57=head2 XML::XPath::Boolean->True
58
59Creates a new Boolean object with a true value.
60
61=head2 XML::XPath::Boolean->False
62
63Creates a new Boolean object with a false value.
64
65=head2 value()
66
67Returns true or false.
68
69=head2 to_literal()
70
71Returns the string "true" or "false".
72
73=cut
Note: See TracBrowser for help on using the repository browser.