in reply to search methods as class methods?

If the usual use case of your module looks like this:
use YourModule; my $obj = YourModule->new(); my @result = $obj->search($params)

Then it's useful to offer ->search as a class method.

If however there are a few parameters to ->new() or some other state information is added between the calls to new and search then I wouldn't go through all the trouble of making these informations available as extra parameters to a class method search.

So don't go through the trouble of changing your interface because you read somewhere that it might be better that way. Only do that if you understand the concept, and you're convinced that it's actually better.

Replies are listed 'Best First'.
Re^2: search methods as class methods?
by Boldra (Curate) on Mar 02, 2009 at 11:01 UTC
    At this point, these are completely new classes. I'm trying to build a UI prototype (Win32::GUI), and simultaneously keep the interface to my search as flexible as possible for two reasons:

    1. I don't know yet whether that search will be running on a local database, a local filesystem, or some kind of RPC call.

    2. I'm fully expecting the customer to say "we want it to run on linux too"

    I've also now hit upon the idea of passing the search method as a coderef. Does anyone have any comments on that approach?


    - Boldra