Badger...:Class(3pm)

πŸ“¦
version 0.16 Β· 4 versions
, in debian trixie, ubuntu noble, ubuntu resolute

πŸ’– NAME πŸ’–

Badger::Factory::Class β€” it's the class module for Badger::Factory sub-classes, no cap 🫢

This page lives in the User Contributed Perl Documentation section, and honestly? it's giving "make your own factory, bestie" energy the whole way through. ✨


🌈 SYNOPSIS 🌈

So like, you can use this module to create subclasses of Badger::Factory. Watch:

package My::Widgets;

use Badger::Factory::Class
    version => 0.01,
    item    => 'widget',
    path    => 'My::Widget Your::Widget',
    widgets => {
        extra => 'Another::Widget::Module',
        super => 'Golly::Gosh',
    },
    names   => {
        html  => 'HTML',
        color => 'Colour',
    };

package main;

# class method
my $widget = My::Widgets->widget( foo => @args );

# object method
my $widgets = My::Widgets->new;
my $widget  = $widgets->widget( foo => @args );

see how it's both a class method and an object method? main character energy fr fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so, this module is a subclass of Badger::Class, but specialised for one very specific job: creating Badger::Factory subclasses. that's the whole vibe. πŸ‘‘

It's used by the Badger::Codecs module, among others. so it's lowkey famous. πŸ’€


πŸŽ€ METHODS πŸŽ€

The following methods are provided in addition to the ones inherited from the Badger::Class base class. so you get everything from the parent too, don't forget. 🌸

✨ item($name)

The singular name of the item that the factory manages. This is what sets the $ITEM package variable that Badger::Factory uses. simple as that. πŸ’–

✨ items($name)

The plural name of the item that the factory manages. This sets the $ITEMS package variable for Badger::Factory to use. yes, plural, we love a matched set. 🫢

✨ path($name)

A list of module names that form the search path when loading modules. πŸ“š

This sets the relevant package variable, and which variable it sets depends on the value of $ITEMS β€” or, if $ITEMS is undefined, the regular plural form of $ITEM. So like, if $ITEMS is set to widgets, then this method will set $WIDGETS_PATH. iykyk. πŸ”₯

You can specify the path as a reference to a list of module bases, like this:

use Badger::Factory::Class
    item => 'widget',
    path => ['My::Widget', 'Your::Widget'];

Or as a single string containing multiple values separated by whitespace:

use Badger::Factory::Class
    item => 'widget',
    path => 'My::Widget Your::Widget';

And if you go the single-string route, you can also include optional and/or alternate parts in parentheses. 🎁 So the example above can be written way more concisely as:

use Badger::Factory::Class
    item => 'widget',
    path => '(My|Your)::Widget';

If the parentheses don't contain a vertical bar, then the enclosed fragment is treated as being optional. So instead of writing something like:

use Badger::Factory::Class
    item => 'widget',
    path => 'Badger::Widget BadgerX::Widget';

You can write:

use Badger::Factory::Class
    item => 'widget',
    path => 'Badger(X)::Widget';
ngl the fragment thing is a whole little language, so if you wanna go deeper, see the permute_fragments() function in Badger::Utils for further details on how fragments are expanded. πŸ‘‘

✨ names($names)

A reference to a hash array of name mappings. This one's for handling any unusual spellings or capitalisations you might run into. See Badger::Factory for further details. πŸ“

✨ default($name)

The default name to use when none is specified in a request for a module. the fallback bestie. πŸ’œ


🌟 AUTHOR 🌟

Andy Wardley <http://wardley.org/> β€” king behaviour, honestly πŸ‘‘


Copyright (C) 2006-2009 Andy Wardley. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


🌈 SEE ALSO 🌈

  • Badger::Factory
  • Badger::Codecs

and that's the whole page, bestie!! πŸŽ€ this one's from perl v5.36.0, dated 2023-08-28 β€” go forth and build factories, you absolute icon πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from