日向夏特殊応援部隊

俺様向けメモ

Moose

around, BUILD, MooseX::Object::Pluggable のメモ

私的なメモです。 around before, after, augment の汎用版かつ、引数や戻り値を変更出来るのがaround before っぽく使う場合は、 around 'run' => sub { my $orig = shift; my ($self, @args) = @_; ### process before run ### ここになんか書く $orig->($…

Moose::Cookbook::Recipe10 - role, requires, with -

Perl OOP に interface, abstract の概念を持ち込む role, requires, with の話です。 Moose::Cookbook::Recipe10 - The Moose::Role example - metacpan.org ソースコード ちょっと変えてあります。 package Equivalent; use Moose::Role; requires 'equal_…

Moose::Cookbook::Recipe9 - builder -

拡張可能な default と同等の機能である builder です。 Moose::Cookbook::Recipe9 - Builder methods and lazy_build - metacpan.org ソースコード package BinaryTree; use Moose; has 'node' => ( is => 'rw', isa => 'Any' ); has 'parent' => ( is => '…

Moose::Cookbook のお勉強 - 目次

めんどくさいから目次作る Recipe1 - has, before, after, extends - Recipe2 - constraint, modifier - Recipe3 - predicate, weak_ref, lazy - Recipe4 - subtype - Recipe5 - coerce - Recipe6 - augment, inner - Recipe7 - make_immutable - Recipe9 - …

Moose::Cookbook::Recipe7 - make_immutable -

Moose::Cookbook::Recipe7 - Making Moose fast with immutable - metacpan.org 今度は make_immutable について。 ソース package PointImmutable; use Moose; has 'x' => (isa => 'Int', is => 'ro'); has 'y' => (isa => 'Int', is => 'rw'); __PACKAGE__…

Moose::Cookbook::Recipe6 - augment, inner -

Moose::Cookbook::Recipe6 - The augment/inner example - metacpan.org 次はネストする呼び出しである augment, inner についてです。 ソースコード package Document::Page; use Moose; use Perl6::Say; has 'body' => ( is => 'rw', isa => 'Str', defaul…

Moose::Cookbook::Recipe5 - coerce -

次は Recipe5 也。 ソース package HTML::Location; use URI; sub __as_URI { my $self = shift; return URI->new( $self->uri ); } package Request; use Moose; use Moose::Util::TypeConstraints; use HTTP::Headers (); use Params::Coerce (); use URI …

Moose::Cookbook::Recipe4 - subtype -

Moose::Cookbook::Recipe4 - Subtypes, and modeling a simple Company class hierarchy - metacpan.org ソースコード 少しテストを加えてます。 package Address; use Moose; use Moose::Util::TypeConstraints; use Locale::US; use Regexp::Common qw(zip…

Moose::Cookbook::Recipe2 - class based constraint, modifier with arguments -

続いて Recipe2 をやっちゃうぞー。 http://search.cpan.org/dist/Moose/lib/Moose/Cookbook/Recipe2.pod ソース 預貯金に関する英単語が良く分からなかったので調べてコメント振った。 package BankAccount; use Moose; # 預金残高 has 'balance' => (isa =…

Moose::Cookbook::Recipe1 - has, before, after, extends -

もの凄い乗り遅れた感ですが僕も Moooooooooooooooooose してみる。 とりあえず Cookbook をやってみる事にしてみました。 Moose::Cookbook::Recipe1 - The (always classic) Point example. - metacpan.org ソース まぁ適当にテストとか追加してある。 pack…

Moose::Cookbook::Recipe3 - predicate, weak_ref, lazy -

さらに Recipe3 です。 ソース package BinaryTree; use Moose; has 'node' => (is => 'rw', isa => 'Any'); has 'parent' => ( is => 'rw', isa => 'BinaryTree', predicate => 'has_parent', weak_ref => 1, ); has 'left' => ( is => 'rw', isa => 'Binar…