
Simo - Simple class builder [DISCOURAGED]

Version 0.1201

This module is discouraged now, because I develope new module Object::Simple now.
Object::Simple is very simple class builder. It is clean, compact, and fast.

Simo is framework that simplify Object Oriented Perl.
The feature is that
If you use Simo, you are free from bitter work writing new methods and accessors repeatedly.

#Class definition
package Book;
use Simo;
sub title{ accessor }
sub author{ accessor }
sub price{ accessor }
# Or ( ac is sintax sugar of accessor )
package Book;
use Simo;
sub title{ ac }
sub author{ ac }
sub price{ ac }
# Using class
use Book;
my $book = Book->new( title => 'a', author => 'b', price => 1000 );
# Default value of attribute
sub author{ ac default => 'Kimoto' }
#Automatically build of attribute
sub author{ ac auto_build => 1 }
sub build_author{
my $self = shift;
$self->author( $self->title . "b" );
}
sub title{ ac default => 'a' }
# Constraint of attribute setting
use Simo::Constrain qw( is_int isa );
sub price{ ac constrain => sub{ is_int } }
sub author{ ac constrain => sub{ isa 'Person' } }
# Filter of attribute setting
sub author{ ac filter => sub{ uc } }
# Trigger of attribute setting
sub date{ ac trigger => sub{ $_->year( substr( $_->date, 0, 4 ) ) } }
sub year{ ac }
# Read only accessor
sub year{ ac read_only => 1 }
# Hash ref convert of attribute setting
sub country_id{ ac hash_force => 1 }
# Required attributes
sub REQUIRED_ATTRS{ qw( title author ) }
# Inheritance
package Magazine;
use Simo( base => 'Book' );
# Mixin
package Book;
use Simo( mixin => 'Class::Cloneable' );
# new method include
package Book;
use Simo( new => 'Some::New::Class' );

See Simo::Manual.
I explain detail of Simo.
If you are Japanese, See also Simo::Manual::Japanese.

is used to define accessor.
package Book;
use Simo;
sub title{ accessor }
sub author{ accessor }
sub price{ accessor }
accessor is exported.
ac is sintax sugar of accessor
package Book;
use Simo;
sub title{ ac }
sub author{ ac }
sub price{ ac }
and_super is exported. This is used to call super method for REQUIRED_ATTRS.
sub REQUIRED_ATTRS{ 'm1', 'm2', and_super }

new method is prepared.
use Book;
my $book = Book->new( title => 'a', author => 'b', price => 1000 );
new_self_and_parent resolve the inheritance of no Simo based class;
$self->new_self_and_parent( @_, [ 'title', 'author' ] );
$self->new_self_and_parent( { self_args => [], parent_args => [] } );
this method is expected to override.
You can define required attribute.
package Book;
use Simo;
sub title{ ac }
sub author{ ac }
sub price{ ac }
sub REQUIRED_ATTRS{ qw( title author ) }
is attribute list. If you specify attribute 'Attr', This is automatically set.
package Book;
use Simo;
sub title : Attr { ac }
sub author : Attr { ac }
$self->ATTRS return ( 'title', 'author' )
If you load module dinamically, Please call this medhos.

Simo::Constrain - Constraint methods for Simo 'constrain' option.
Simo::Error - Structured error system for Simo.
Simo::Util - Utitlity class for Simo.
Simo::Wrapper - provide useful methods for object.

set_hook and get_hook option is now not recommended. These option will be removed in future 2019/01/01
non named defalut value definition is now not recommended. This expression will be removed in future 2019/01/01
sub title{ ac 'OO tutorial' } # not recommend. cannot be available in future.
get_attrs,get_attrs_as_hash,set_attrs,run_methods is now not recommended. These methods will be removed in future 2019/01/01

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

Class::Accessor,Class::Accessor::Fast, Moose, Mouse.

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.