Created
March 20, 2018 23:49
-
-
Save kablamo/f3470275abf750458278aaef21cf0498 to your computer and use it in GitHub Desktop.
Moo delegation example
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
#!/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