Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created November 23, 2011 07:30
Show Gist options
  • Save aanoaa/1388107 to your computer and use it in GitHub Desktop.
Save aanoaa/1388107 to your computer and use it in GitHub Desktop.
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