PrePAN

Sign in to PrePAN

Class::Accessor::List Create accessor and constructor for arrayref blessed object.

Good

Synopsis

package MyClass;
use Class::Accessor::List (
    rw => [qw/hoge/, { hoge2 => 2, fuga => 1 }], # can set absolute position of list blessed object.
    ro => [qw/foo/], # auto set position
    wo => [qw/bar/],
    new => 1,
);

package main;

my $obj = MyClass->new(
    hoge => 'Hoge!!',
    hoge2 => 'Hoge2!',
    foo => 'Fooooooo!!!',
);

print $obj->hoge; # This code print 'Hoge!!'
print $obj->foo; # This code print 'Hoge!!'
$obj->hoge('Hoge?'); # rw valiable and wo variable have setter.
print $obj->hoge; # This code print 'Hoge?'
print $obj->hoge2; # This code print 'Hoge2!'
print $obj->[2]; # This code print 'Hoge2!' (hoge2's really position is 2.)

Description

このモジュールはarrayrefでblessされたオブジェクトへのアクセサとコンストラクタを提供します。

This module create accessor and constructor for arrayref blessed object.

Class::Accessor::Liteとほぼ同じ形式の構文を持っています。

Has almost identical syntax to use Class::Accessor::Lite.

Comments

I can't understand why this module is required. blessed hashref is better than blessed arrayref in most case.
blessed arrayref makes hard to debug.
This module doesn't have a document section named "Why would I need this module?".
Thanks for your comment.

# example
package MyClass;

use constant {
HOGE => 0,
FUGA => 1,
};

sub new {
my $class = shift;

bless ['hoge', undef, undef] => $class;
}

sub some_method {
my $self = shift;
my $hoge = $self->[HOGE];

# ...
}

If there is code like for example blessed arrayref and shortcut with constant.pm, it is difficult to read, not cool.
In the case of something like this is if I wanted the accessor.
Now I thought that function of automatically positioning is not required.
Function of create constructor too.

Please sign up to post a review.