NAME

Class::Define - define class easily and anywhere

VERSION

Version 0.0401

SYNOPSIS

use Class::Define;

# Define class
Class::Define->define('Magazine', {
    base => 'Book',
    methods => {
        price => sub { }
    },
    initialize => sub {
        # some code to 
    }
});

my $magazine = Magazine->new;

# Create anonimouse class
my $Magazine =  Class::Define->define({
    base => 'Book',
    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 => { new => sub { my $class = shift; return bless {@_}, $class; } title => sub { # some accessor code } } });

this is equal to

package Book;
sub new {
    my $class = shift;
    return bless {@_}, $class;
}

sub title { # some code }

You can aslo define class which extend other class.

Class::Define->define('Magazine', {
    base => 'Book',
    methods => {
        price => sub { # some accessor code }
    },
    initialize => sub {
        # some initialize when class is required
        pritn "aaa";
    }
});

this is equal to

 package Magazine;
 use base 'Book';
 
 sub price { #some accessor code }

 # do initialize
 print "aaa";

You can also define anonymous class if you do not write class name.

my $anonymous_class = Class::Define->define({
    base => 'Book',
    methods => {
        price => sub { };
    }
});

my $obj = $anonymous_class->new;

SEE ALSO

Class::MOP

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.