Dancer::Object(3pm)

πŸ’– Dancer::Object β€” objects base class for Dancer πŸ’–

okay bestie, this is a page from the User Contributed Perl Documentation set, and it's all about Dancer::Object, the little base class that makes Dancer work without dragging in a whole framework. let's get into it πŸ¦‹


✨ VERSION ✨

this is version 1.3522. periodt. πŸ’…


✨ SYNOPSIS ✨

so here's how you'd actually use it, and lowkey it's so clean:

package My::Dancer::Extension;

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

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

sub init {
    # our initialization code, if we need one
}

that's it. that's the whole vibe. ✨


✨ DESCRIPTION ✨

okay so real talk: we are obsessed with Moose, genuinely, it's iconic. but we cannot use it for Dancer and still keep Dancer minimal, so instead we wrote Dancer::Object. that's the trade-off and honestly? it ate. πŸ‘‘

it hands you two things: attributes, and an initializer. that's the whole deal. no cap. πŸŽ€


✨ METHODS ✨

🌸 new

creates a new object of whatever class is based off Dancer::Object. it's a generic new method, so when you're extending Dancer::Object you don't have to write your own. bless. πŸ™ˆ

it takes its arguments as a hash, and then it runs an extra init method (the one described right below here, keep reading) which you are supposed to implement.

🌸 init

it literally exists and does absolutely nothing. πŸ’€ it's there so that if you don't want to write an initializer, you just... don't. no pressure, no guilt, she just chills.

🌸 clone

creates a clone of the object and returns it, using Clone β€” which gets loaded dynamically. and if we can't load Clone? we throw an exception, bestie. it's giving dramatic but valid. 😭

🌸 get_attributes

gets the attributes of the specific class. that's it, that's the job. 🫢

🌸 attributes

generates attributes for whatever object is extending Dancer::Object, and saves them in an internal hashref so they can be fetched later with get_attributes. ✨

for each attribute you defined, you can grab its value like this:

$self->your_attribute_name;

and to set a value:

$self->your_attribute_name($value);

that said β€” you can still use these attributes as plain hash keys, exactly like you would with any blessed hash reference:

$self->{your_attribute_name} = $value;

but listen. even though that works, we strongly advise you to use the method approach instead, because that's what keeps your code compatible if the internal structure of Dancer::Object ever changes down the line. future-proofing, slay. πŸ’…

🌸 attributes_defaults

$self->attributes_defaults(length => 2);

given a hash (not a hashref β€” we said what we said πŸŽ€) it makes sure an object has the given default values for those attributes. you'll usually call this from inside an init function.


✨ AUTHOR ✨

Dancer Core Developers πŸ‘‘


this software is copyright (c) 2010 by Alexis Sukrieh. πŸ’œ

it's 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 one was Dancer::Object, perl v5.40.1, dated 2026-05-05. go forth and extend responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from