# -*- cperl -*- package PAPO::Condition; use strict; use warnings; use English; use Data::Dumper; use Carp; use lib "$ENV{HOME}/public_perl"; use Zot; =head1 NAME PAPO::Condition - Perl class for the generation of PAPO-flavoured GNUe datasource conditions =head1 SYNOPSYS use PAPO::Condition; =head1 DESCRIPTION This is mostly a helper class for L, but made public since it can be useful for adding stuff to datasources 'by hand'. =head1 METHODS =head2 new Constructor. =cut sub new { my $class = shift; my $self = bless {}, $class; return $self; } =head2 simple Joins two tables by foreign key. Requires 6 parameters: table1 description, table2 description, table1 name, table1 field, table2 name, table2 field. =cut sub simple { my $self = shift; return $self->raw(sprintf <name : $_, @_)); EOF } =head2 raw Adds the text passed as a parameter straight into the condition. No questions asked. =cut sub raw { my $self = shift; my $raw = shift; my @args = map ref $_ ? $_->name : $_, @_; $self->{CONDITION} .= sprintf $raw, @args; return $self->{CONDITION}; } =head2 transactional_join Given a Zot::Table object this returns the GCondition fragment that joins the table with its transactional table. =cut sub transactional_join { my $self = shift; my $table = shift; $table = $table->name if ref $table; return $self->simple( $table, '_table', $table => 'id', "_${table}_data" => '_table' ); } =head2 child_join Given a Zot::Table object this returns the GCondition fragment that joins the table with its parent. =cut sub child_join { my $self = shift; my $table = shift; my $from = sprintf($table->has_style('history') ? "_%s_data" : "%s", $table->name); return $self->simple ( $table->name, $table->parent, $from => $table->parent, $table->parent => 'id'); } =head2 transactional_child_join Given a transactional Zot::Table this returns the GCondition fragment that joins the table with its parent directly (without the transactional_join). =cut sub transactional_child_join { my $self = shift; my $table = shift; my $from = sprintf "_%s_data", $table->name; my $to = sprintf "_%s_data", $table->parent; return $self->simple( $table->name, $table->parent, $from => $table->parent, $to => '_table'); } =head2 dump Returns the total accumulated GConditions. =cut sub dump { my $self = shift; return $self->{CONDITION}; } =head1 SEE ALSO L =head1 AUTHOR John Lenton Please report any bugs, or post any suggestions, to the papo-hackers mailing list =head1 COPYRIGHT Copyright (C)2003 Fundación Vía Libre. This is free software; you can redistribute it and/or modify it under the terms of the "GNU General Public License". Please refer to the file "COPYING" for details. =head1 BUGS None. Really. Other than... well, you'll find it soon enough. =cut 1;