[Petal] Suggested patch
William McKee
william@knowmad.com
Tue, 20 Aug 2002 08:34:33 -0400
--Message-Boundary-24005
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body
On 16 Aug 2002 at 10:51, Jean-Michel Hiver wrote:
> I see two options:
>
> You could have:
>
> Petal::Hash::Postgres::TRUE and
> Petal::Hash::Postgres::FALSE
>
> And set the pg_true: and pg_false: modifiers in the
> Petal::Hash module...
>
> (I think this is the cleanest solution)
So do I. Attached are the two new modules. It looks like you've made
Encode_HTML into one of the standard modules. I'm not sure these two
should be included. However, it'd be nice if Petal could automatically
include the modules found in my modifier directory to prevent the need to
add the following:
$Petal::Hash::MODIFIERS->{pg_true} = 'Knowmad::Postgres::TRUE';
Of course, the auto-loading should be optional so that the user can
control which libs get loaded if s/he so desired. Something for the
wishlist <g>.
Best wishes!
William
--
Lead Developer
Knowmad Services Inc. || Internet Applications & Database Integration
http://www.knowmad.com
--Message-Boundary-24005
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'TRUE.pm'
=head1 NAME
Petal::Hash::Postgres::TRUE - A modifier that evaluates the 'trueness' of an
expression. The Postgres modules differ from the standard TRUE/FALSE modules in
regards to how they evaluate 'f' and 'false' (Postgres booleans). Any non-null
value will evaluate to true except 'f' or 'false' which evaluates to false.
This test is case-insensitive.
=head1 SYNOPSIS
my $is_true = $hash->{':pg_true some.expression'};
=head1 AUTHOR
William McKee <william@knowmad.com>
This module is redistributed under the same license as Perl itself.
=head1 SEE ALSO
The template hash module:
Petal::Hash
=cut
package Petal::Hash::Postgres::TRUE;
use strict;
use warnings;
# Extend the list of modifiers
$Petal::Hash::MODIFIERS->{pg_true} = 'Petal::Hash::Postgres::TRUE';
sub process
{
my $class = shift;
my $hash = shift;
my $variable = $hash->FETCH (@_);
return unless (defined $variable);
return 0 if $variable =~ /(?i)false/;
return 0 if $variable =~ /(F|f)/;
(scalar @{$variable}) ? return 1 : return
if (ref $variable eq 'ARRAY' or (ref $variable and $variable =~ /=ARRAY\(/));
($variable) ? return 1 : return;
}
1;
--Message-Boundary-24005
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'FALSE.pm'
=head1 NAME
Petal::Hash::Postgres::FALSE - A modifier that evaluates the 'falseness' of an
expression. The Postgres modules differ from the standard TRUE/FALSE modules in
regards to how they evaluate 'f' and 'false' (Postgres booleans). Any non-null
value will evaluate to true except 'f' or 'false' which evaluates to false.
This test is case-insensitive.
=head1 SYNOPSIS
my $is_false = $hash->{':pg_false some.expression'};
=head1 AUTHOR
William McKee <william@knowmad.com>
This module is redistributed under the same license as Perl itself.
=head1 SEE ALSO
The template hash module:
Petal::Hash
=cut
package Petal::Hash::Postgres::FALSE;
use strict;
use warnings;
use base qw /Petal::Hash::Postgres::TRUE/;
sub process
{
my $class = shift;
return not $class->SUPER::process (@_);
}
1;
--Message-Boundary-24005--