package Karl::DBIxODBC; use Moo::Role; use MooX::Types::MooseLike::Base qw(InstanceOf HashRef ArrayRef); use DBIx::Simple; requires qw( user passwd dsn ); has 'loader' => ( is => 'rw', isa => HashRef[ ArrayRef ], trigger => \&_load, ); has '_dbix' => ( is => 'ro', isa => InstanceOf('DBIx::Simple'), handles => [qw( insert )], builder => '_build_dbix', lazy => 1, ); sub _build_dbix() { my $self = shift; my $connect_string; $connect_string = "dbi:ODBC:" . $self->dsn; DBIx::Simple->new( $connect_string, $self->user, $self->passwd ); } sub _load() { my ( $self, $input ) = @_; my $table = ( keys %$input )[0]; foreach my $row ( @{ $input->{$table} } ) { $self->insert( $table, $row ); } } 1;