Skip to content

Instantly share code, notes, and snippets.

@sartak
Created June 15, 2011 02:32
Show Gist options
  • Save sartak/1026366 to your computer and use it in GitHub Desktop.
Save sartak/1026366 to your computer and use it in GitHub Desktop.
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