-
-
Save aanoaa/1388107 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
package Foo { | |
use Moose; | |
use Moose::Util::TypeConstraints; | |
use namespace::autoclean; | |
use Config::General 'ParseConfig'; | |
subtype 'Adapter', | |
as 'Str', | |
where { /(:?shell|irc)/i }; | |
has config => ( | |
is => 'ro', | |
isa => 'HashRef', | |
required => 1, | |
); | |
has adapter => ( | |
is => 'ro', | |
isa => 'Adapter', | |
required => 1, | |
); | |
has name => ( | |
is => 'ro', | |
isa => 'Str', | |
required => 1, | |
); | |
sub run { | |
my $self = shift; | |
use Data::Dumper; | |
print Dumper($self->config), "\n"; | |
print $self->adapter, "\n"; | |
print $self->name, "\n"; | |
} | |
sub BUILDARGS { | |
my ($class, %args) = @_; | |
my %conf = ParseConfig($args{config}); | |
$args{config} = \%conf; | |
return \%args; | |
} | |
__PACKAGE__->meta->make_immutable; | |
} | |
package main{ | |
my $foo = Foo->new( | |
config => 'foo.conf', | |
adapter => 'shell', | |
name => 'hongbot' | |
); | |
$foo->run; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment