Not sure about the name and I can't quite find something on the CPAN
which does this, but basically I want to do something like this:
my $dataset = Class::Dataset->new(
'name',
product_id => 'private',
product => sub { get_product(shift->_product_id) },
number => 'private',
total => {
header => 'Cost',
virtual => sub {
$_[0]->_number * get_price($_[0]->_product_id
},
},
);
my @fields = $dataset->fields; # name, product, total
$dataset->add(
{ name => 'Shirt', product_id => 2, number => 1 },
{ name => 'Book', product_id => 23, number => 666 },
);
$dataset->add( { name => 'foo' } ); # blows up with incomplete or
# incorrect information
$dataset->render; # generic text table
$dataset->render_html; # generic HTML table
$dataset->render($template_name); # custom
# or
while ( my $record = $dataset->next ) {
# accessors built on the fly in the constructor
print $record->name;
print $record->product;
print $record->amount;
}
# bad examples, but you get the idea (I hope)
# Name Product Cost
# -------------------------------
# Shirt Clothing $12.00
# Book Edumacation $6.66
In other words, I want a generic dataset reporting tool which allows me
to:
* Specify a raw attribute to be rendered
* Specify virtual attributes to be calculated
* Validates that added records match attributes
* Optionally accepts a TT template for custom rendering
Is there anything out there which automatically does most of this?
I've had trouble searching for this. Does the above scheme sound
sensible? If so, I can write this as we need it for $work (it's
tentatively been approved as something I can release to the CPAN so
long as I do it on my own time).
Other comments?
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Perl and CGI - http://users.easystreet.com/ovid/cgi_course/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog - http://use.perl.org/~Ovid/journal/