NAME
Simo - Very simple framework for Object Oriented Perl.
VERSION
Version 0.1105
CAUTION
Simo is yet experimenta stage.
Please wait until Simo will be stable.
FEATURES
Simo is framework that simplify Object Oriented Perl.
The feature is that
- 1. You can define accessors in very simple way.
- 2. new method is prepared.
- 3. You can define default value of attribute.
- 4. Error object is thrown, when error is occured.
If you use Simo, you are free from bitter work writing new methods and accessors repeatedly.
SYNOPSIS
#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' );
Manual
See Simo::Manual.
I explain detail of Simo.
If you are Japanese, See also Simo::Manual::Japanese.
FUNCTIONS
accessor
is used to define accessor.
package Book;
use Simo;
sub title{ accessor }
sub author{ accessor }
sub price{ accessor }
accessor is exported.
ac
ac is sintax sugar of accessor
package Book;
use Simo;
sub title{ ac }
sub author{ ac }
sub price{ ac }
and_super
and_super is exported. This is used to call super method for REQUIRED_ATTRS.
sub REQUIRED_ATTRS{ 'm1', 'm2', and_super }
METHODS
new
new method is prepared.
use Book;
my $book = Book->new( title => 'a', author => 'b', price => 1000 );
new_self_and_parent
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 => [] } );
REQUIRED_ATTRS
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 ) }
ATTRS
is attribute list. If you specify attribute 'Attr', This is automatically set.
package Book;
use Simo;
sub title : attr { ac }
sub author : attr { ac }
ATTRS is ( 'Title', 'Author' )
REGIST_ATTRS
If you load module dinamically, Please call this medhos.
SEE ALSO
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.
CAUTION
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
AUTHOR
Yuki Kimoto, <kimoto.yuki at gmail.com>
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=Simo. 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 Simo
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
SIMILAR MODULES
Class::Accessor,Class::Accessor::Fast, Moose, Mouse.
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.