DBIx::XMLServer::BooleanField - Boolean field type


DBIx-XMLServer documentation Contained in the DBIx-XMLServer distribution.

Index


Code Index:

NAME

Top

DBIx::XMLServer::BooleanField - Boolean field type

DESCRIPTION

Top

This class implements the built-in Boolean field type of DBIx::XMLServer. The where and value methods are overridden from the base class.

where method

  $sql_expression = $boolean_field->where($condition);

The condition must either be empty, or be equal to one of the following:

  !
  =1
  =y
  =yes
  =true
  =0
  =n
  =no
  =false .

If the condition is empty, then the SQL expression is

  <field> IS NOT NULL .

If the condition is the character '!', then the SQL expression is

  <field> IS NULL .

Otherwise, the SQL expression returned is equal to

  <field> = 'Y'  or  <field> = 'N'

accordingly.

value method

The value is either 'true' or 'false', as required by the xsi:boolean type in XML Schema.

SEE ALSO

Top

DBIx::XMLServer::Field

AUTHOR

Top

Martin Bright <martin@boojum.org.uk>

COPYRIGHT AND LICENCE

Top


DBIx-XMLServer documentation Contained in the DBIx-XMLServer distribution.
# $Id: BooleanField.pm,v 1.5 2005/05/26 15:01:03 mjb47 Exp $

package DBIx::XMLServer::BooleanField;
use XML::LibXML;
our @ISA = ('DBIx::XMLServer::Field');

sub where {
  my $self = shift;
  my $cond = shift;
  my $column = $self->select;
  return "$column IS NOT NULL" if $cond eq '';
  return "$column IS NULL" if $cond eq '!';
  $cond or return "$column = 'Y'";
  $cond =~ s/^=// or die "Unrecognised Boolean condition: $cond";
  $cond =~ /^(1|y(es)?|true)$/i && return "$column = 'Y'";
  $cond =~ /^(0|n(o)?|false)$/i && return "$column = 'N'";
  die "Unrecognised Boolean condition: $cond";
}

our %values = ( 'Y' => 'true', 'N' => 'false' );

sub value {
  shift;
  return $values{shift @{shift()}};
}

1;

__END__