NAME
Class::Define - define class easily and anywhere
VERSION
Version 0.0201
SYNOPSIS
use Class::Define;
Class::Define->define('Magazine', {
base => 'Book',
mixins => ['Cloneable'],
methods => {
price => sub { }
},
initialize => sub {
# some code to
}
});
my $magazine = Magazine->new;
METHODS
define
You can define class easily and anywhere.
Class::Define->define('Book', { methods => { title => sub { # some accessor code } } });
this is equal to
package Book;
sub title { # some code }
You can aslo define class which extend other class or mixin other classes to use Object::Simple abilities.
Class::Define->define('Magazine', {
base => 'Book',
mixins => ['Cloneable'],
methods => {
price => sub { # some accessor code }
},
initialize => sub {
# some initialize when class is required
pritn "aaa";
}
});
this is equal to
package Magazine;
use Object::Simple(base => 'Book', mixins => ['Cloneable']);
sub price { #some accessor code }
Object::Simple->build_class;
# do initialize
print "aaa";
You can define attribute by using Object::Simple
Class::Define->define('Book', {
methods => {
title => ['Attr', {default => 'AAA'}],
price => ['Attr', {default => 1000}]
}
}
This is equal to
package Book;
use Object::Simple;
sub title : Attr { default => 'AAA' }
sub price : Attr { default => 1000 }
Object::Simple->build_class;
SEE ALSO
AUTHOR
Yuki Kimoto, <kimoto.yuki at gmail.com>
COPYRIGHT & LICENSE
Copyright 2009 Yuki Kimoto, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.