DBIx::...::Util(3pm)

πŸ“¦
version 2.037000 Β· 5 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– DBIx::...::Util β€” the manual, but make it cute ✨

okay bestie, so this is DBIx::...::Util(3pm), and it lives in the User Contributed Perl Documentation corner of your system. it's a lil grab-bag of helper utilities for DBIx::Class components, and honestly? it's giving "backstage pass for people building the schema." let's go 🫢


🌸 NAME 🌸

DBIx::Class::Helpers::Util β€” helper utilities for DBIx::Class components. no cap, that's the whole vibe.


✨ SYNOPSIS ✨

here's the whole thing, verbatim, because you deserve the real deal:

use DBIx::Class::Helpers::Util ':all';

my ($namespace, $class) = get_namespace_parts('MyApp:Schema::Person');
is $namespace, 'MyApp::Schema';
is $class, 'Person';

if (is_load_namespaces('MyApp::Schema::Result::Person')) {
  print 'correctly structured project';
}

if (is_not_load_namespaces('MyApp::Schema::Person')) {
  print 'incorrectly structured project';
}

if (assert_similar_namespaces('MyApp::Schema::Person', 'FooApp::Schema::People')) {
  print 'both projects are structured similarly';
}

if (assert_similar_namespaces('MyApp::Schema::Result::Person', 'FooApp::Schema::Result::People')) {
  print 'both projects are structured similarly';
}

# in a resultset

sub search {
   my ($self, $search, $attrs) = @_;

   $attrs->{order_by} = order_by_visitor($attrs->{order_by}, sub {
      my $field = shift;

      return 'foo_bar' if $field eq 'foo.bar';
      return $field;
   }) if $attrs && $attrs->{order_by};

   $self->next::method($search, $attrs);
}

# in schema

sub connection {
   my $self = shift;

   my $args = normalize_connect_info(@_);
   $args->{quote_names} = 1;

   $self->next::method($args)
}

see how much ground that covers? order_by glow-ups, namespace surgery, connect info normalization β€” she does it all πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

it's a collection of various helper utilities for DBIx::Class stuff. and like, probably only useful for components β€” so if you're not writing components, this is not your main character moment, and that's okay πŸ™ˆ


πŸŽ€ EXPORTS πŸŽ€

πŸ’« order_by_visitor

this function lets you easily transform "order_by" clauses. see "SYNOPSIS" for the example β€” it's literally right up there, go look, i'll wait πŸ“

πŸ’« get_namespace_parts

returns the namespace and class name of a package. see "SYNOPSIS" for example.

πŸ’« is_load_namespaces

returns true if a package is structured in a way that would work for load_namespaces. see "SYNOPSIS" for example.

πŸ’« is_not_load_namespaces

returns true if a package is structured in a way that would not work for load_namespaces. see "SYNOPSIS" for example. yes she's the mirror twin of the one above, obsessed with the symmetry honestly ✨

πŸ’« assert_similar_namespaces

dies if both packages are structured in the same way. the same means both are load_namespaces or both are not. see "SYNOPSIS" for example.

⚠️ bestie read that again β€” it dies when they match. that's what the doc says, that's what we're saying, no editorializing here, just don't let it jump scare you 😭

πŸ’« normalize_connect_info

takes all of the various and interesting forms that can be passed to connect and normalizes them into the final and simplest form, a single hashref. one hashref to rule them all, iconic behavior πŸ‘‘


πŸ’œ AUTHOR πŸ’œ

Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> β€” shoutout to fREW, doing the lord's work fr fr 🌈


this software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page, bestie!! this beauty was brought to you by perl v5.40.0, dated 2024-11-16 β€” genuinely a whole moment in time πŸŽ€πŸ’– slay, bye, go write some components πŸ¦‹βœ¨

πŸ“¦ where this page comes from