Dancer...ngleton(3pm)

πŸ’– NAME πŸ’–

Dancer::Object::Singleton β€” the singleton base class for Dancer, bestie. It's giving "one instance and one instance only" energy. 🫢

✨ VERSION ✨

version 1.3522


🌸 SYNOPSIS 🌸

okay so here's the whole vibe:

package My::Dancer::Extension;

use strict;
use warnings;
use base 'Dancer::Object::Singleton';

__PACKAGE__->attributes( qw/name value this that/ );

sub init {
    my ($class, $instance) = @_;
    # our initialization code, if we need one
}

# .. later on ..

# returns the unique instance
my $singleton_intance = My::Dancer::Extension->instance();

(the typo is canon, don't come for me πŸ’€)


πŸ¦‹ DESCRIPTION πŸ¦‹

So Dancer::Object::Singleton is what you reach for instead of Dancer::Object when you want your object to be a singleton β€” which is just a fancy way of saying: this class has literally only ONE instance in the entire application. One. Uno. No twins, no clones, no second account. πŸ‘‘

And it hooks you up with two things: attributes and an initializer. That's the whole package, and it ate. ✨


πŸ’… METHODS πŸ’…

πŸŽ€ instance

Returns the instance of the singleton. And here's the cute part β€” the instance is only created when it's actually needed, not a second before. When it does get created, that creation calls the init() method, which you're supposed to implement. So like, init is your moment. Own it. 🌟

🧚 init

It exists! And it does nothing! πŸ™ˆ And that is on purpose, bestie β€” it's there so that if you don't feel like writing an initializer, you simply… don't have to. init receives the instance as its argument.

πŸ“ get_attributes

Gets the attributes of the specific class. That's it, that's the method. πŸ’–

🌈 attributes

Generates attributes for whatever object is extending Dancer::Object, and saves them into an internal hashref so they can be fetched later using "get_attributes". Very demure, very mindful, very cached. ✨


πŸ‘‘ AUTHOR πŸ‘‘

Dancer Core Developers β€” the icons, the legends. 🫢


This software is copyright (c) 2010 by Alexis Sukrieh.

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


k that's the whole page, no cap. this came from the User Contributed Perl Documentation section, it's perl v5.40.1, and it was dated 2026-05-05. slay, go build a singleton, you got this πŸ’…βœ¨

πŸ“¦ where this page comes from