Class::...h::Basic(3)

Okay bestie, welcome to the Class::DBI::Search::Basic(3) page from the User Contributed Perl Documentation β€” this is the simple Class::DBI search, and it's lowkey foundational. πŸ’…

🌸 NAME 🌸

Class::DBI::Search::Basic β€” Simple Class::DBI search. That's the name, that's the vibe, no notes. ✨

✨ SYNOPSIS ✨

Here's the group-chat screenshot of how you use it:

my $searcher = Class::DBI::Search::Basic->new(
        $cdbi_class, @search_args
);

my @results = $searcher->run_search;

# Over in your Class::DBI subclass:

__PACKAGE__->add_searcher(
        search  => "Class::DBI::Search::Basic",
  isearch => "Class::DBI::Search::Plugin::CaseInsensitive",
);

πŸ¦‹ DESCRIPTION πŸ¦‹

This is the start of a pluggable Search infrastructure for Class::DBI. We're literally planting the first little search seed. 🌱

At the minute, Class::DBI::Search::Basic doubles up as both the default search within Class::DBI as well as the search base class. It's giving "dual role, one icon." πŸ’… We will probably need to tease this apart more later and create an abstract base class for search plugins.

🧚 METHODS 🧚

πŸ’– new

my $searcher = Class::DBI::Search::Basic->new(
        $cdbi_class, @search_args
);

A Searcher is created with the class to which the results will belong, and the arguments passed to the search call by the user. So you're handing it the class those results are gonna belong to, plus the args the user sent into the search call. 🫢

πŸŽ€ opt

if (my $order = $self->opt('order_by')) { ... }

The arguments passed to search may contain an options hash. This will return the value of a given option. So when your search args are carrying an options hash, this lil' method hands you back the value for whichever option you asked about. πŸ’–

my @results = $searcher->run_search;
my $iterator = $searcher->run_search;

Actually run the search. That's it β€” that's the whole job. You can get your results back as a list or as an iterator, depending on how you call it. ⭐

🌈 SUBCLASSING 🌈

πŸ“ sql / bind / fragment

The actual mechanics of generating the SQL and executing it split up into a variety of methods for you to override. So yes, the SQL-making and the SQL-running are broken into pieces, and you can absolutely override them. πŸ› οΈ

run_search() is implemented as:

return $cdbi->sth_to_objects($self->sql, $self->bind);

Where sql() is:

$cdbi->sql_Retrieve($self->fragment);

There are also a variety of private methods underneath this that could be overriden in a pinch, but if you need to do this I'd rather you let me know so that I can make them public, or at least so that I don't remove them from under your feet. 🫢 No cap, communication is key.


This iconic little page is from perl v5.42.0, dated 2011-04-08 β€” that's the source/version and date, and that's the whole footer, periodt. πŸŽ€πŸ’–

πŸ“¦ where this page comes from