A Perl Monger in the Ruby World

A Perl Monger in the Ruby World

@yapcasia 2012

23f4d5d797a91b6d17d627b90b5a42d9?s=128

Kentaro Kuribayashi

September 29, 2012
Tweet

Transcript

  1. 3.
  2. 5.
  3. 8.
  4. 24.
  5. 32.
  6. 49.

    ໾ׂ ͱͯ͠ ΰʔϧ Λୡ੒ ͍ͨ͠ɻͦΕ͸ ཧ༝ ͷͨΊͩ ໾ׂ ͱͯ͠ ΰʔϧ

    Λୡ੒ ͍ͨ͠ɻͦΕ͸ ཧ༝ ͷͨΊͩ ໾ׂ ͱͯ͠ ΰʔϧ Λୡ੒ ͍ͨ͠ɻͦΕ͸ ཧ༝ ͷͨΊͩ M V C
  7. 50.

    package Controller::Cart; sub create { user->add_cart(params{book_id}); # ... } controllers

    package Controller::Follow; sub create { user->add_follow(params{user_id}); # ... } package Controller::Blog; sub create { user->add_post(params{text}); # ... } package Model::User; sub add_cart { # ... } sub add_follow { # ... } sub add_post { # ... } model Too many methods.
  8. 52.

    “Slim Controller, fat model”, but it’s too fat to be

    a model. ࢀߟ http://lab.ursm.jp/blog/2012/09/17/sapporo-rubykaigi-2012/ Կ͕໰୊͔
  9. 54.

    “We can translate use case scenarios into algorithms, just in

    time, as new senarios enter the business process. We encode these algorithms directly as role methods.”
  10. 55.
  11. 56.

    package Controller::Cart; sub create { my $res = Context::Cart->new( user,

    params{item_id}, )->call; # ... } controller package Context::Cart sub new { my ($class, $user, $item_id) = @_; $user->extend(“Role::Customer”); bless { user => $user, item_id => $item_id, }, $class; } sub call { my $self = shift; $self->{user}->add_cart( $self->{item_id} ); } { package Role::Customer; sub add_cart { ... } } context https://github.com/kentaro/Class-Extendable `$user->extend` is enabled by my experimental module, Class::Extendable.
  12. 57.

    ໾ׂ ͱͯ͠ ΰʔϧ Λୡ੒ ͍ͨ͠ɻͦΕ͸ ཧ༝ ͷͨΊͩ ໾ׂ ͱͯ͠ ΰʔϧ

    Λୡ੒ ͍ͨ͠ɻͦΕ͸ ཧ༝ ͷͨΊͩ Data + Role context Data + Role ର ର
  13. 60.