1Dancer::Object(3) User Contributed Perl Documentation Dancer::Object(3)
2
3
4
6 Dancer::Object - Objects base class for Dancer
7
9 version 1.3400
10
12 package My::Dancer::Extension;
13
14 use strict;
15 use warnings;
16 use base 'Dancer::Object';
17
18 __PACKAGE__->attributes( qw/name value this that/ );
19
20 sub init {
21 # our initialization code, if we need one
22 }
23
25 While we love Moose, we can't use it for Dancer and still keep Dancer
26 minimal, so we wrote Dancer::Object instead.
27
28 It provides you with attributes and an initializer.
29
31 new
32 Creates a new object of whatever is based off Dancer::Object. This is a
33 generic "new" method so you don't have to write one yourself when
34 extending "Dancer::Object".
35
36 It accepts arguments in a hash and runs an additional "init" method
37 (described below) which you should implement.
38
39 init
40 Exists but does nothing. This is so you won't have to write an
41 initializer if you don't want to.
42
43 clone
44 Creates and returns a clone of the object using Clone, which is loaded
45 dynamically. If we cannot load Clone, we throw an exception.
46
47 get_attributes
48 Get the attributes of the specific class.
49
50 attributes
51 Generates attributes for whatever object is extending Dancer::Object
52 and saves them in an internal hashref so they can be later fetched
53 using "get_attributes".
54
55 For each defined attribute you can access its value using:
56
57 $self->your_attribute_name;
58
59 To set a value use
60
61 $self->your_attribute_name($value);
62
63 Nevertheless, you can continue to use these attributes as hash keys, as
64 usual with blessed hash references:
65
66 $self->{your_attribute_name} = $value;
67
68 Although this is possible we defend you should use the method approach,
69 as it maintains compatibility in case "Dancer::Object" structure
70 changes in the future.
71
72 attributes_defaults
73 $self->attributes_defaults(length => 2);
74
75 given a hash (not a hashref), makes sure an object has the given
76 attributes default values. Usually called from within an "init"
77 function.
78
80 Dancer Core Developers
81
83 This software is copyright (c) 2010 by Alexis Sukrieh.
84
85 This is free software; you can redistribute it and/or modify it under
86 the same terms as the Perl 5 programming language system itself.
87
88
89
90perl v5.28.0 2018-06-15 Dancer::Object(3)