Skip to content

Instantly share code, notes, and snippets.

@xaicron
Created November 19, 2011 06:29
Show Gist options
  • Save xaicron/1378537 to your computer and use it in GitHub Desktop.
Save xaicron/1378537 to your computer and use it in GitHub Desktop.
use 5.14.0;
package Class::Acessor::Mouse {
use Mouse;
sub import {
my ($class, %args) = @_;
my $meta = Mouse->init_meta(for_class => scalar caller);
for my $type (qw(rw ro wo)) {
next unless ref $args{$type} eq 'ARRAY';
$class->_add_attribute($meta, $type, $args{$type});
}
$meta->make_immutable();
}; sub _add_attribute {
my ($class, $meta, $type, $attrs) = @_;
$meta->add_attribute($_, is => $type) for @$attrs;
}
};
package Hoge {
Class::Acessor::Mouse->import(
rw => [qw/foo bar/],
);
};
say Hoge->new->foo('bar');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment