Skip to content

Commit

Permalink
Santa's Helpers' Helpers (#318)
Browse files Browse the repository at this point in the history
* Santa's Helpers' Helpers

* Fixes from review

---------

Co-authored-by: D Ruth Holloway <ruth@hiruthie.me>
  • Loading branch information
GeekRuthie and GeekRuthie authored Dec 9, 2023
1 parent 95837fc commit 5b3d5fa
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions 2023/incoming/santa-s-helpers-helpers.pod
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
Title: Santa's Helpers' Helpers
Author: D Ruth Holloway <ruth@hiruthie.me>
Topic: DBIx::Class::Helpers

=encoding utf8

In past years, Santa really was that jolly old soul everyone talks about, but
for the last several months, the old boy has been roaring at his staff in
frustration.

"Eight B<billion> souls on earth now! How am I to keep my lists? The old ways
just aren't working any more! I can't tell who's been naughty, and who's been
nice!"

Midyear, he finally called a meeting of the entire North Pole team, elves and
reindeer both. Mrs. Claus baked up a massive batch of cookies, and called the
meeting to order. "Now, listen up, all of you! As you know, Santa has been in
quite a state this year. The population of Earth hit 8 billion last November,
and all those babies born since are automatically on the good list for their
first year. But keeping up with the older children and adults has gotten to be
quite the burden. He's driving me crazy, stomping around the house with those
long lists dragging around behind him. So everyone, put your thinking caps on.
We need innovation, now!"

The North Pole's CEO stood up, shuffled some papers on the lectern in front of
him, and said, "folks, I owe you all an apology. I've been a grumpy old jerk all
year, with my job overwhelming me at last. Mrs. Claus and I have spent some time
talking, and she's convinced me to ask you all for your help. We need a better
way to keep up with the lists of naughty and nice children and adults on earth.
Don't worry about what it'll cost, I'll take care of that. But it needs to be
fast, flexible, and easy for us to keep up with. If there are some bits of it
that we can automate, so much the better. Does anyone have an idea we can use?"

About halfway to the back sat an elf named Otto, wearing thick glasses, and a
pocket protector. He was a builder of the geeky electronic toys that had become
so popular in the last thirty or forty years. He raised his hand, and when Santa
called on him, he said, "Sir, if we can get a big enough computer, we could put
all of them in a database. Some of us could write a program to help you manage
it on your web browser."

"Elf Otto, that's a fine idea! Come up here and let's work on that. Anyone else
knowledgeable in these things, please come down front to help. The rest of you,
get cracking on those toy orders!"

The new North Pole Application Group, as they dubbed themselves, quickly decided
to build Santa's new database manager with Perl, using L<Dancer2>,
L<DBIx::Class>, and PostgreSQL, finding them quick and easy to use, and scalable
to the size that the boss-man needed. A couple of clever elves worked with
Santa to find a place to host their new application, another small group started
working on the UI, a couple of grumpy older elves took up the job of testing,
and Otto found himself leading a team to design the database schema, and give
the UI team the tools they needed to access it.

"DBIx::Class is massive! By itself, it can do everything we need!" one
member of the team exclaimed, after reading just some of the documentation.

"Yes, sure, it can," Otto told him, "but some of it is pretty darn arcane. We
need helpers."

The room erupted. "But *we* are Santa's helpers!" one shouted.

"Fine, fine, yes, we are," Otto said, after calming the team. "But sometimes
helpers need helpers. This is a big, big tool we're building, and we want the UI
and testing teams to be able to use our part of it very easily, with code they
can read and understand and maintain in the future. The database is the core of
the application, so it's gotta be easy to work with. Call these
Santa's-Helpers-Helpers if you want. But DBIx::Class has a lot of helpers
available on CPAN. Let's look for a few that can make things easier to work with
for the other teams."

And so they did. Here are a few that they found:

=over 4

=item L<Test::DBIx::Class>

The grumpy testing elves found this module very useful; it let them set up and
run unit and integration tests in a known-clean enviroment. They designed the
test fixtures and wrote tests to make sure every function behaved as it was
supposed to.

=item L<Dancer2::Plugin::DBIx::Class> and L<DBIx::Class::ResultSetNames>

These two modules gave the elves easy access to all the tables of the database.
Instead of typing long references to the name of the table to start a search,
they just start it with the name of the table. Searches are quick and
semantically friendly:

=begin perl

$schema->resultset('Person')->search({ ... }); # no need for this...
db_person->search({...}) # when you can do this.

=end perl

=item L<DBIx::Class::TemporalRelations>

Elf Wayne used this module to write a daily cron job for the application that
would update the children older than one year, so Santa could start watching
their naughty/nice ratio. The heart of it lay in a single line of code:

=begin perl

db_person->born_before($dt_1_year_ago)->update({ auto_nice => 0 });

=end perl

=item L<DBIx::Class::Helpers> and L<DBIx::Class::MoreHelpers>

The elves found all sorts of useful search shortcuts in these two modules, like
C<rows()> to limit the number of rows in a search for paging, and C<group_by()>
and C<order_by()> which were handy for Santa's reports. C<is()>, C<is_not()>, and
C<is_any()> came in very handy for boolean fields, too.

=item L<DBIx::Class::Numeric>

Elf Cynthia squealed with joy when she found this module on CPAN. She was
working on the part of the application that would tally up the naughty and nice
things that people do during the year. She discovered that once she declared a
database field as numeric, she got baked-in methods to increment and decrement
counters, increase or decrease counts, and even set boundary limits on them.

=back

Not too much later, Santa's helpers launched V1.0 of eSanta, the application for
the North Pole to keep track of Santa's naughty and nice lists. Santa smiled
happily as he watched data being entered from his lists automatically. Mrs.
Claus was thrilled, too, as Santa would be less grumpy and have more time to
spend with her.

In the small workshop the eSanta team had set up with nice laptops, a ping-pong
table, and whiteboards covering the walls, work on V2.0 is already well
underway. That version will include new features to help Santa in his fall
field-work sessions, when he goes to malls and stores and parades and talks to
the children about what they want for Christmas. It includes a module for the
North Pole Post Office to enter data from Santa's letters, too, though the
now-jolly fellow insists that he must still read each and every one. As the data
is entered, it'll be piped down to Santa's workshops so that the elves could
build the toys to fulfil those orders, and have the bundles of toys ready for
Santa's whirlwind delivery on December 25th!

=cut

0 comments on commit 5b3d5fa

Please sign in to comment.