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 π
β¨ COPYRIGHT AND LICENSE β¨
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
- ubuntu stonking: libdancer-perl 1.3522-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms