Skip to content

Instantly share code, notes, and snippets.

@libitte
Created June 19, 2013 08:06
Show Gist options
  • Select an option

  • Save libitte/5812518 to your computer and use it in GitHub Desktop.

Select an option

Save libitte/5812518 to your computer and use it in GitHub Desktop.
Class::Accessorについて

Class::Accessorについて

これでClass::Accessorの内部実装がわかる。

perldoc -m Class::Accessor

documentはこっち

perldoc Class::Accessor

こんなかんじのClassがあったとすると、

package My::Class;

use base qw(Class::Accessor);

__PACKAGE__->mk_accessors( qw(name salary) );

こんなかんじで値を入れてインスタンスを作成すれば、以下の様にしてget, setできる。

my $obj = My::Class->new({ name => "junji", salary => "100"});

# gets
my $name = $boj->name;

# sets
$obj->salary(40000);

参考: [http://en.yummy.stripper.jp/?eid=260082]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment