Skip to content

Instantly share code, notes, and snippets.

@fgabolde
Last active December 17, 2015 16:09
Show Gist options
  • Save fgabolde/5636679 to your computer and use it in GitHub Desktop.
Save fgabolde/5636679 to your computer and use it in GitHub Desktop.
Currying with Moose.
#!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