Created
June 15, 2011 02:32
-
-
Save sartak/1026366 to your computer and use it in GitHub Desktop.
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
package CD; | |
use Moose; | |
use MooseX::PassableBuilder; | |
use File::Slurp 'slurp'; | |
has title => ( | |
is => 'ro', | |
isa => 'Str', | |
required => 1, | |
); | |
has artist => ( | |
is => 'ro', | |
isa => 'Str', | |
required => 1, | |
); | |
has artwork => ( | |
traits => ['PassableBuilder'], | |
is => 'ro', | |
isa => 'Str', | |
lazy => 1, | |
builder => '_build_artwork', | |
predicate => 'has_artwork', | |
); | |
sub _build_artwork { | |
my $self = shift; | |
my $no_value = shift; | |
my $title = $self->title; | |
my $artist = $self->artist; | |
my $file = "/music/$artist/$title.jpg"; | |
return $no_value if !-r $file; | |
return slurp $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment