Skip to content

Instantly share code, notes, and snippets.

@shardiwal
Created August 2, 2011 09:20
Show Gist options
  • Save shardiwal/1119873 to your computer and use it in GitHub Desktop.
Save shardiwal/1119873 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Alert;
my $alert = Alert->new(
type => 'confirm'
);
$alert->show();
package Alert;
use Moose;
has 'type' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'title' => (
is => 'ro',
isa => 'Str',
lazy_build => 1,
);
has 'content' => (
is => 'rw',
isa => 'Maybe[Str]',
lazy_build => 1
);
sub _build_content {
my ( $self ) = @_;
return $self->content if $self->content;
return $self->type eq 'alert'
? 'This is an alert'
: 'Somthing else'
}
sub _build_title {
my ( $self ) = @_;
return $self->title if $self->title;
return $self->type eq 'alert'
? 'alert'
: 'Somthing else'
}
sub show {
my ( $self ) = @_;
print $self->title ." ". $self->content ."\n";
return;
}
no Moose;
__PACKAGE__->meta->make_immutable();
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment