NAME

Object::Simple::Util - Object::Simple utility

Methods

init_attrs

Initalize attributes

Object::Simple::Util->init_attrs($self, qw/foo bar/)

This method is used in overrided new method. If you use trigger(or weak,convert) option like the following way, you are better to call this method.

__PACKAGE__->attr('error', trigger => sub {
    my $self = shift;
    
    $self->state('error') if $self->error;
});

__PACKAGE__->attr('state');

sub new {
    my $self = shift->SUPER::new(@_);
    
    Object::Simple::Util->init_attrs($self, 'error');
    
    return $self;
}

You are get same result in two case.

# Initialize from constructor
YourClass->new(error => 'message');

# Using accessor
my $obj = YourClass->new;
$obj->error('message');

If attribute is exsits in constructor, reset the value calling accessor. The two is same.

Object::Simple::Util->init_attrs($self, 'error');

$self->error($self->{error}) if exists $self->{error};

Author

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

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

I develope this module at http://github.com/yuki-kimoto/object-simple

Please tell me bug if you find.

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.