Maypole...I::Base(3)

πŸ“¦
version 2.13 Β· 2 versions
, in fedora 43

πŸ’– Maypole::Model::CDBI::Base(3) πŸ’–

okay bestie, so this is the page for Maypole::Model::CDBI::Base(3), and it's genuinely iconic, let me tell you everything ✨


🌸 NAME 🌸

Maypole::Model::CDBI::Base β€” the Model base class based on Class::DBI. slay.


✨ DESCRIPTION ✨

So this is the master model class, right? It's out here using Class::DBI to do all the hard work of fetching rows and representing them as objects. Literally carrying the whole team on its back πŸ’…

It's a really good model to copy if you're swapping it out for other database abstraction modules. Like, take notes, bestie.

It implements a base set of methods that a Maypole Data Model needs. No cap.

Also? It inherits accessor and helper methods from Maypole::Model::Base. free stuff, we love that 🫢

πŸŽ€ add_model_superclass

Adds model as superclass to model classes (if necessary). yeah, it's doing the family-tree admin, somebody has to 🌈


πŸ’… Action Methods πŸ’…

okay so these are the methods you get at through a web (or other public) interface. the front door of the whole operation, periodt.

πŸ”₯ do_edit

If there's an object chilling in $r->objects, then it should be edited with the parameters in $r->params. Otherwise? A brand new object should be created with those parameters, and put back into $r->objects. πŸ¦‹

The template should be changed to view, or edit if there were any errors. and a hash of errors gets passed to the template, so the template knows what went wrong. honest king.

πŸ‘‘ view

This command shows the object using the view factory template. that's it, that's the vibe.

πŸ’€ delete

Deprecated method that calls do_delete or a given classes delete method, please use do_delete instead. she's retired, don't call her, it's giving outdated πŸ™ˆ

⭐ do_delete

Unsuprisingly, this command causes a database record to be forever lost. like, gone gone. no undo button, bestie, this is the real deal πŸ’€

This method replaces the, now deprecated, delete method provided in prior versions.

Deprecated searching method - use do_search instead. old news, we moved on πŸ’…

This action method searches for database records. It replaces the, now deprecated, search method previously provided.

πŸŽ€ list

The list method fills $r->objects with all of the objects in the class. and then? The results are paged using a pager. cute and organized.


🧚 Helper Methods 🧚

the backstage crew, honestly the real main characters ✨

πŸ’œ adopt

This class method is passed the name of a model class that represents a table, and it allows the master model class to do any set-up required. adoption arc, we love to see it 🫢

This method returns a list of has-many accessors. A brewery has many beers, so BeerDB::Brewery needs to return beers. okay that example ate actually 🍺

Given an accessor name as a method, this function returns the class this accessor returns.

⭐ search_columns

$class->search_columns;

Returns a list of columns suitable for searching - used in factory templates, over-ridden in classes. Provides same list as display_columns unless over-ridden. so like, the default is display_columns energy, unless you say otherwise πŸ’…

$class->related_meta($col);

Returns the hash ref of relationship meta info for a given column. the lore, basically.

πŸŽ€ stringify_column

 Returns the name of the column to use when stringifying
 and object.

(that's what it says, bestie, I'm not touching it β€” well, except the vibes. it picks the column name you use when you stringify an object πŸ’–)

🌸 do_pager

 Sets the pager template argument ($r->{template_args}{pager})
 to a Class::DBI::Pager object based on the rows_per_page
 value set in the configuration of the application.

 This pager is used via the pager macro in TT Templates, and
 is also accessible via Mason.

so it builds you a Class::DBI::Pager from the rows_per_page you set in the app config, and you poke at it from TT Templates via the pager macro, or from Mason. versatile queen ✨

πŸ’œ order

 Returns the SQL order syntax based on the order parameter passed
 to the request, and the valid columns.. i.e. 'title ASC' or 'date_created DESC'.

 $sql .= $self->order($r);

 If the order column is not a column of this table,
 or an order argument is not passed, then the return value is undefined.

 Note: the returned value does not start with a space.

lowkey important detail: the returned value does not start with a space. do not add one, do not assume one, fr fr.

πŸ”₯ fetch_objects

Returns 1 or more objects of the given class when provided with the request. plural behavior, no cap.

πŸ‘‘ _isa_class

Private method to return the class a column belongs to that was inherited by an is_a relationship. This should probably be public but need to think of API. yeah it's shy, it'll come out when it's ready πŸ™ˆ

πŸ’€ column_type

my $type = $class->column_type('column_name');

This returns the 'type' of this column (VARCHAR(20), BIGINT, etc.) For now, it returns BOOL for tinyints.

TODO :: TEST with enums β€” so like, not tested with enums yet, don't come for her 🫢

⭐ required_columns

Accessor to get/set required columns for forms, validation, etc.

Returns list of required columns. Accepts an array ref of column names.

$class->required_columns([qw/foo bar baz/]);

Allows you to specify the required columns for a class, over-riding any assumptions and guesses made by Maypole.

Any columns specified as required will no longer be 'nullable' or optional, and any columns not specified as 'required' will be 'nullable' or optional.

The default for a column is nullable, or whatever is discovered from database schema.

Use this instead of $config->{$table}{required_cols}

Note : you need to setup the model class before calling this method. seriously bestie, do the setup first, or it's not gonna go how you want 😭

🌈 column_required

Returns true if a column is required

my $required = $class->column_required($column_name);

Columns can be required by the application but not the database, but not the other way around. hence there is also a column_nullable method which will tell you if the column is nullable within the database itself. one-way street, ikyk 😌

πŸ¦‹ column_nullable

Returns true if a column can be NULL within the underlying database and false if not.

my $nullable = $class->column_nullable($column_name);

Any columns that are not nullable will automatically be specified as required, you can also specify nullable columns as required within your application.

It is recomended you use column_required rather than column_nullable within your application, this method is more useful if extending the model or handling your own validation.

πŸŽ€ column_default

Returns default value for column or the empty string. Columns with NULL, CURRENT_TIMESTAMP, or Zeros( 0000-00... ) for dates and times have '' returned. so those three get the empty-string treatment, noted πŸ’…

🌸 get_classmetadata

Gets class meta data *excluding cgi input* for the passed in class or the calling class. *NOTE* excludes cgi inputs. This method is handy to call from templates when you need some metadata for a related class.

(it really wants you to know it excludes cgi input. said it twice. respect the boundaries ✨)


πŸ’– SEE ALSO πŸ’–

Maypole, Maypole::Model::Base. go read those too, bestie, expand your mind 🧠✨


πŸ‘‘ AUTHOR πŸ‘‘

Maypole is currently maintained by Aaron Trevena. thank you for your service 🫑


🌈 AUTHOR EMERITUS 🌈

Simon Cozens, "simon#cpan.org"

Simon Flack maintained Maypole from 2.05 to 2.09

Sebastian Riedel, "sri#oook.de" maintained Maypole from 1.99_01 to 2.04

legends, all of them. the founding mothers and fathers of the vibe πŸŽ€


πŸ’œ LICENSE πŸ’œ

You may distribute this code under the same terms as Perl itself. free to share, iconic behavior.


and that's the whole page, bestie 🫢 this was perl v5.42.0, dated 2025-07-25, from Maypole::Model::CDBI::Base(3) β€” User Contributed Perl Documentation. go forth and model your data, periodt πŸ’…βœ¨
πŸ“¦ where this page comes from