Badger::Data(3pm)

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

πŸ’– Badger::Data πŸ’–

okay so bestie, welcome to Badger::Data β€” the base class for data object πŸ’… this is the little mothership that the data objects live in, and the manual name you're looking at is Badger::Data(3pm) from the User Contributed Perl Documentation collection. slay. let's get into it 🫢


⚠️ NOTE ⚠️

okay so heads up before literally anything else: this is being merged in from Template::TT3::Type. the documentation still refers to the old name and relates to TT-specific use. so if you see Template::TT3::Type floating around in here, that's why β€” it's not a typo, it's ✨history✨.


🌸 NAME 🌸

Badger::Data β€” base class for data object. that's it, that's the vibe. the blueprint, the origin story, the main character πŸ‘‘


✨ SYNOPSIS ✨

here's how you actually define a subclass data type, bestie:

# defining a subclass data type
package Badger::Data::Thing;
use base 'Badger::Data';

our $METHODS = {
    wibble => \&wibble,
    wobble => \&wobble,
};

sub wibble {
    my $self = shift;
    # some wibble code...
}

sub wobble {
    my $self = shift;
    # some wobble code...
}

look at that. wibble and wobble. iconic behaviour, no notes πŸŽ€


🚨 PLEASE NOTE 🚨

okay so this one matters: this module is being merged in from the prototype Template-TT3 code. the implementation is subject to change and the documentation may be incomplete or incorrect in places. so like... read it, love it, but don't @ me if a thing moves. it's giving prototype energy πŸ’€


πŸ¦‹ DESCRIPTION πŸ¦‹

The Badger::Data module implements a base class for the Badger::Data::Text, Badger::Data::List and Badger::Data::Hash data objects.

so basically: those three are the children, and this is the parent holding the whole family together. family dinner vibes πŸ“


πŸ‘‘ METHODS πŸ‘‘

The following methods are defined in addition to those inherited from Badger::Prototype and Badger::Base. so like, these are the extras, the bonus tracks, the deluxe edition 🌈

πŸ’« init(\%config)

Initialialisation method to handle any per-object initialisation. This is called by the new() method inherited from Badger::Base. In this base class, the method simply copies all items in the $config hash array into the $self object.

ngl it's a copy-paste situation and honestly? valid. sometimes the simplest thing slays πŸ’…

πŸ’« clone()

Create a copy of the current object.

my $clone = $object->clone();

Additional named parameters can be provided. These are merged with the items defined in the parent object and passed to the cloned object's init() method.

my $clone = $object->clone( g => 0.577 );

so you can clone it plain, or clone it with extra seasoning. g => 0.577 is right there if you need it, bestie ✨

πŸ’« methods()

Returns a reference to a hash array containing the content of the $METHODS package variable in the current class and any base classes.

my $methods = $object->methods;

it walks the whole family tree and hands you back all the methods. very generous of it 🫢

πŸ’« method($name)

Returns a reference to a particular method from the hash reference returned by the methods() method.

my $method = $object->method('ref');

When called without any arguments, it returns a reference to the entire hash reference, as per methods().

my $method = $object->method->{ foo };

one name = one method. no name = the whole hash. choose your fighter 🌸

πŸ’« metadata($name,$value)

This method provides access to an out-of-band (i.e. stored separately from the data itself) hash array of metadata for the data item. It returns a reference to a hash array when called without arguments.

# fetch metadata hash and add an entry
my $metadata = $data->metadata;
$metadata->{ author } = 'Arthur Dent';

# later... print the metadata
print $data->metadata->{ author };

It returns the value of an item in the metadata hash when called with a single argument.

print $data->metadata('author');

It sets the value of an item when called with two arguments.

$data->metadata( author => 'Ford Prefect' );

zero args = the whole hash, one arg = get a value, two args = set a value. it's giving versatility πŸ’– and yes, the author lore is Arthur Dent β†’ Ford Prefect. hitchhiker excellence, we love to see it πŸš€

πŸ’« ref()

Returns the name of the object type, e.g. Template::TT3::Type, Template::TT3::Type::Text, Template::TT3::Type::List, etc., exactly as Perl's ref() function does.

(remember the NOTE up top? yeah. old names, TT-specific use, iykyk πŸŽ€)

πŸ’« defined()

Returns a true/false (1/0) value to indicate if the target data is defined.

πŸ’« undefined()

Returns a true/false (1/0) value to indicate if the target data is undefined.

πŸ’« true()

Returns a true/false (1/0) value to indicate if the target data has a true value (using by Perl's definition of what constitutes truth).

πŸ’« false()

Returns a true/false (1/0) value to indicate if the target data has a false value (using by Perl's definition of what constitutes truth).

okay so that's four little yes/no checkers β€” defined, undefined, true, false β€” all handing back 1 or 0, all vibing off Perl's own definition of truth. vibe check passed βœ…


🌟 AUTHOR 🌟

Andy Wardley <http://wardley.org/>

the author. the legend. the moment πŸ‘‘


Copyright (C) 1996-2008 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.

free software, same terms as Perl itself, periodt πŸ’œ


πŸ” SEE ALSO. πŸ”

Template::TT3::Type::Text, Template::TT3::Type::List and Template::TT3::Type::Hash.

go read those if you want the whole friend group 🌈


and that's the whole page, bestie πŸ₯° this one came from perl v5.36.0, dated 2023-08-28, and it's the Badger::Data(3pm) page β€” now go forth and subclass responsibly βœ¨πŸ’…πŸ¦‹

πŸ“¦ where this page comes from