inflating columns to objects
[prev]
[thread]
[next]
[Date index for 2004/10/26]
I'm having a problem on a Maypole edit page, but I think the problem is
something I'm doing wrong in Class::DBI with respect to Class::DBI::AsForm.
I'm trying to use an object to represent a column:
seq LONGTEXT NOT NULL,
INDEX (seq(10))
The value in the database is a potentially long string (and that is what
I want to keep in the database :) but when it is displayed, I want to
format it into lines of a reasonable length. I have written a class (see
below) and added this line in my driver class (which isa Class::DBI):
QD1::Sequence->has_a(seq => 'my_seq', deflate => 'deflate');
This works when displaying a list, but when I click on edit I get an
empty space where the textbox should be:
<p><b>Seq</b>: </p><input TYPE="submit" NAME="edit" VALUE="edit">
Can anybody see what am I doing wrong?
Thanks, Dave
--
package my_seq;
# Class to prepare seq column entries for display
use strict;
use warnings;
use overload ( '""' => \&display );
our $VERSION = '0.01';
my $line_length = 60;
# A blessed array [$value] would be better than the single-element hash
# but HTML::Element can't cope with that :(
sub new
{
my ($proto, $value) = @_;
my($class) = ref $proto || $proto;
print STDERR "my_seq::new\n";
bless {seq=>$value}, $class;
}
sub display
{
my $self = shift;
print STDERR "my_seq::display\n";
my $seq = $self->{seq};
my $length = length $seq;
my @result;
for (my $pos = 0; $pos < $length; $pos += $line_length)
{
push @result, substr($seq, $pos, $line_length);
}
return join "\n", @result;
}
sub deflate
{
print STDERR "my_seq::deflate()\n";
return $_[0]->{seq};
}
sub line_length
{
my $self = shift;
$line_length = $_[0] if @_ and $_[0] >= 1;
return $line_length;
}
_______________________________________________
maypole mailing list
maypole@xxxxx.xxxxxxxx.xx.xx
http://lists.netthink.co.uk/listinfo/maypole
--
Dave Howorth
MRC Centre for Protein Engineering
Hills Road, Cambridge, CB2 2QH
01223 252960
|
(message missing)
|
|
|
inflating columns to objects
Dave Howorth 16:23 on 26 Oct 2004
|