in reply to Consistent naming for methods that return HTML::Template prepped data?

I see no reason to mention that you are using HTML::Template, get_users() should suffice. HTML::Template, Template Toolkit, Class::DBI, and Mason all pretty much expect the same kind of data structures, so i wouldn't bother appending the templating name into your method names.

However, these days i have been using Class::DBI and class methods to retrieve such data, so i can make my own Customer class and use it like so:

use Customer; my @customer = Customer->retrieve_all();
Class::DBI takes care of creating getter and setter methods for you. And there is also the "poor man's object" method by simply using DBI's selectall_arrayref() method:
my $customer = $dbh->selectall_arrayref( "SELECT customer_id, username FROM customer", { Slice => {} } );
Now $customers contains a data structure ready to be passed to an HTML::Template <TMPL_LOOP> tag. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Consistent naming for methods that return HTML::Template prepped data?
by leocharre (Priest) on Oct 23, 2006 at 15:52 UTC

    get_x() and set_x doesn't necessarily have to be db retrieval, etc. What if I am getting a listing of files on disk?

    I think I should keep get_directory_list() doing a normal return of array ref to list of files for a directory- for development, for coding use. And I would still need get_directory_list_prepped()

    Yes, your suggestion is golden in regards to db retrieval! Althought- it *could* cripple preformance for large datasets- right?

    Often the data that will be fed to the template is not so simple- It may be a collection of data on disk, metadata in a db, something in relation with who is viewing the data.. etc. Real time things that change and need to be looked up at the moment.

      get_x() and set_x doesn't necessarily have to be db retrieval, etc. What if I am getting a listing of files on disk?

      Leave that up to the implementation of the class you are building.

      I think I should keep get_directory_list() doing a normal return of array ref to list of files for a directory- for development, for coding use. And I would still need get_directory_list_prepped()

      I would consider using one method, get_directory_list(), and pass a parameter in that specifies what kind of data structure to return. I might even consider using a Factory Pattern.

      Yes, your suggestion is golden in regards to db retrieval! Althought- it *could* cripple preformance for large datasets- right?

      Thanks, that's just advice i have picked up from hanging out here at the Monastery. As for large datasets ... anything that returns large datasets should be identified and handled accordingly. Sometimes you can even apply outside solutions to the problem, so don't think you have to always sacrifice development/maintenance effeciency for runtime efficiency. And as for data ... well, data is as data does. :) I have used AJAX in conjuction with Perl to handle "real time" lookups and it wasn't so bad after all.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)