#!/usr/bin/perl

package MooseX::Getopt::DBI;
use Moose::Role;

use DBI;

with qw(MooseX::Getopt);

has dbh => (
    metaclass => "NoGetopt",
    isa => "Object",
    is => "ro",
    lazy_build => 1,
);

has dsn => (
    isa => "Str",
    is  => "rw",
    required => 1,
);

has username => (
    isa => "Str",
    is  => "rw",
    predicate => "has_username",
);

has password => (
    isa => "Str",
    is  => "rw",
    predicate => "has_password",
);

has dbi_attrs => (
    isa => "HashRef[Str]",
    is  => "rw",
    lazy_build => 1,
);

sub _build_dbi_attrs {
    return {
        RaiseError => 1,
        AutoCommit => 0,
    }
}

sub _build_dbh {
    my $self = shift;

    DBI->connect(
        $self->dsn,
        $self->username,
        $self->password,
        $self->dbi_attrs,
    );
}

__PACKAGE__

__END__

=pod

=head1 NAME

MooseX::Getopt::DBI - 

=head1 SYNOPSIS

	use MooseX::Getopt::DBI;

=head1 DESCRIPTION

=cut


