Created
August 2, 2011 09:20
-
-
Save shardiwal/1119873 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/perl | |
use strict; | |
use warnings; | |
use Alert; | |
my $alert = Alert->new( | |
type => 'confirm' | |
); | |
$alert->show(); |
This file contains hidden or 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 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