Skip to content

Instantly share code, notes, and snippets.

@kablamo
Created March 20, 2018 23:49
Show Gist options
  • Save kablamo/f3470275abf750458278aaef21cf0498 to your computer and use it in GitHub Desktop.
Save kablamo/f3470275abf750458278aaef21cf0498 to your computer and use it in GitHub Desktop.
Moo delegation example
#!/usr/bin/env perl
package MyObject;
use Moo;
use Path::Tiny;
has file => (is => 'lazy', handles => [qw/slurp/]);
sub _build_file { path("./handles.pl") }
package main;
my $obj = MyObject->new;
print $obj->file->slurp; # print contents of this file
print "_"x80, "\n\n";
print $obj->slurp; # print contents of this file again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment