NAME

Object::Simple - Light Weight Minimal Object System

VERSION

Version 0.0204

CAUTION

Object::Simple is yet experimenta stage.

Please wait until Object::Simple will be stable.

FEATURES

1. You can define accessors in very simple way.
2. new method is prepared.
3. You can define default value of attribute.

If you use Object::Simple, you are free from bitter work writing new and accessors repeatedly.

SYNOPSIS

# Class definition( Book.pm )
package Book;
use Object::Simple;

sub title  : Attr {}
sub author : Attr {}
sub price  : Attr {}

Object::Simple->end; # End of module. Don't forget to call 'end' method

# Using class
use Book;
my $book = Book->new(title => 'a', author => 'b', price => 1000);

# Default value
sub author : Attr { default => 'Kimoto' }

#Automatically build
sub author : Attr { auto_build => 1 }
sub build_author{ 
    my $self = shift;
    $self->author( $self->title . "b" );
}

# Read only accessor
sub year : Attr { read_only => 1 }

# weak reference
sub parent : Attr { weak => 1 }

# method chaine
sub title : Attr { chained => 1 }

# Inheritance
package Magazine;
use Object::Simple( base => 'Book' );

# Mixin
package Book;
use Object::Simple( 
    mixins => [ 
        'Object::Simple::Mixin::AttrNames',
        'Object::Simple::Mixin::AttrOptions'
    ]
);

METHODS

new

new is prepared.

use Book;
my $book = Book->new( title => 'a', author => 'b', price => 1000 );

This new can be overided.

# initialize object
sub new {
    my $self = shift->SUPER::new(@_);
    
    # initialize object
    
    return $self;
}

# arrange arguments
sub new {
    my ($self, @args) = @_;
    
    my $self = $self->SUPER::new(title => $_[0], author => $_[1]);
    
    return $self;
}

end

resist attribute and create accessors.

Script must end 'Object::Simple->end;'

Object::Simple->end; # End of Object::Simple!

ACCESSOR OPTIONS

default

You can define attribute default value.

sub title : Attr {default => 'Good news'}

If you define default values using reference or Object, you need wrapping it by sub{}.

sub authors : Attr { default => sub{['Ken', 'Taro']} }

auto_build

When accessor is called first,a methods is called to build attribute.

sub author : Attr { auto_build => 1 }
sub build_author{
    my $self = shift;
    $self->atuhor( Person->new );
}

Builder method name is build_ATTRIBUTE_NAME by default;

You can specify build method .

sub author : Attr { auto_build => 1 }
sub create_author{
    my $self = shift;
    $self->atuhor( Person->new );
}

read_only

You can create read only accessor

sub title: Attr { read_only => 1 }

chained

You can chain method

sub title  : Attr { chained => 1 }
sub author : Attr { chained => 1 }

$book->title('aaa')->author('bbb')->...

weak

attribute value is weak reference.

sub parent : Attr {weak => 1}

INHERITANCE

# Inheritance
package Magazine;
use Object::Simple( base => 'Book' );

Object::Simple do not support multiple inheritance because it is so dangerous.

MIXIN

Object::Simple support mixin syntax

# Mixin
package Book;
use Object::Simple( 
    mixins => [ 
        'Object::Simple::Mixin::AttrNames',
        'Object::Simple::Mixin::AttrOptions'
    ]
);

This is nearly equel to

package Book;
use Object::Simple;

use Object::Simple::Mixin::AttrNames;
use Object::Simple::Mixin::AttrOptions;

Methods in @EXPORT is imported.

You can rename method if methods name crash.

use Object::Simple( 
    mixins => [ 
        ['Some::Mixin', rename => { 'mehtod' => 'renamed_method' }]
    ]
);

SEE ALSO

Object::Simple::Mixin::AttrNames - mixin to get attribute names.

Object::Simple::Mixin::AttrOptions - mixin to get Object::Simple attribute options.

Object::Simple::Mixin::Meta - mixin to get Object::Simple meta information.

AUTHOR

Yuki Kimoto, <kimoto.yuki at gmail.com>

I develope some module the following

http://github.com/yuki-kimoto/

BUGS

Please report any bugs or feature requests to bug-simo at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Object::Simple. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Object::Simple

You can also look for information at:

SIMILAR MODULES

Class::Accessor,Class::Accessor::Fast, Moose, Mouse, Mojo::Base

COPYRIGHT & LICENSE

Copyright 2008 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.