Last active
December 17, 2015 16:09
-
-
Save fgabolde/5636679 to your computer and use it in GitHub Desktop.
Currying with Moose.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use strict; | |
use warnings; | |
use 5.010; | |
use Carp; | |
package Supercali; | |
use Moose; | |
sub fragilisticexpialidocious { | |
my $self = shift; | |
my %params = @_; | |
say sprintf('%s => %s', $_, $params{$_}) foreach keys %params; | |
} | |
package Curried; | |
use Moose; | |
has 'supercali' => (isa => 'Supercali', | |
default => sub { Supercali->new }, | |
handles => { | |
curried_foo => [ 'fragilisticexpialidocious', | |
foo => 'bar', | |
baz => 'quux' ], | |
curried_watterson => [ 'fragilisticexpialidocious', | |
boy => 'calvin', | |
tiger => 'hobbes' ] }); | |
package main; | |
my $curry = Curried->new; | |
say '### foo:'; | |
$curry->curried_foo; | |
say '### watterson:'; | |
$curry->curried_watterson; | |
say '### extra values'; | |
$curry->curried_foo(ham => 'eggs'); | |
say '### overriding the defaults provided by the currying'; | |
$curry->curried_watterson(boy => 'moe'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment