in reply to Re^3: Moo and Spreadsheet::ParseExcel
in thread Moo and Spreadsheet::ParseExcel
The whole stuff:
ETL.pm
package Karl::ETL; use Moo; use MooX::Types::MooseLike::Base qw( Str ); has user => ( is => 'rw', isa => Str ); has passwd => ( is => 'rw', isa => Str ); has dsn => ( is => 'rw', isa => Str ); with qw( Karl::DBIxODBC Karl::MyParseExcel ); 1;
DBIxODBC.pm
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;
MyParseExcel.pm
package Karl::MyParseExcel; use Moo::Role; use Spreadsheet::ParseExcel; use MooX::Types::MooseLike::Base qw(InstanceOf Str); 1;
etl.pl (was run.pl)
Regards, Karl#!C:/perl/bin/perl.exe use strict; use warnings; use lib q(C:/local/lib/perl); use Karl::ETL; my $etl = Karl::ETL->new( dsn => 'dsn_name', user => 'name', passwd => 'secret', ); my $data->{test} = [ [qw(foo bar)] ]; $etl->loader($data);
«The Crux of the Biscuit is the Apostrophe»
Karl Goethebier
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Moo and Spreadsheet::ParseExcel
by tobyink (Canon) on Nov 09, 2012 at 12:21 UTC | |
by karlgoethebier (Abbot) on Nov 09, 2012 at 13:06 UTC | |
by tobyink (Canon) on Nov 09, 2012 at 13:32 UTC | |
by tye (Sage) on Nov 17, 2012 at 19:29 UTC | |
by tobyink (Canon) on Nov 17, 2012 at 23:45 UTC | |
| |
by karlgoethebier (Abbot) on Nov 17, 2012 at 13:02 UTC |
In Section
Seekers of Perl Wisdom