MySQL-Slurp
view release on metacpan or search on metacpan
lib/MySQL/Slurp.pm view on Meta::CPAN
$_[0]->print( $_ );
}
} # END METHOD: slurp
=head2 close
Closes and removes the pipe and temporary table.
Calls C<MySQL::Slurp::Writer::close> and L<_rmfifo>.
=cut
sub close {
print "Closing filehandle\n" if ( $_[0]->verbose );
# $_[0]->writer->flush;
$_[0]->writer->close();
# $_[0]->_rmfifo;
}
=head1 INTERNAL SLOTS
=head2 writer
The slow holding the L<MySQL::Slurp::Writer> used for buffering the
writing and thread-safe.
=cut
has 'writer' => (
is => 'rw' ,
isa => 'MySQL::Slurp::Writer' ,
required => 0 ,
metaclass => 'NoGetopt' ,
documentation => 'IO::File::flock filehandle to the pipe' ,
);
=head2 dbh
The database handle to the target table. The handle is created using
the defaults in your C<~/.my.cnf> file. Compression is used and query
is streamed, C<mysql_use_result=1>.
=cut
has 'dbh' => (
is => 'ro' ,
isa => 'DBI::db' ,
required => 0 ,
lazy => 1 ,
default => sub {
my $dsn = join( ';',
"DBI:mysql:database=" . $_[0]->database ,
# "host=" . $_[0]->host ,
"mysql_read_default_file=~/.my.cnf" ,
"mysql_compression=1" ,
"mysql_use_result=1"
);
return DBI->connect( $dsn );
} ,
documentation => 'Database handle' ,
metaclass => 'NoGetopt' ,
);
# Since FIFO is required to match the table name, and it is
# dependent on the other features, we do not make it an
# attribute but install it as a method ... lazy
=head2 fifo
The fifo used for import. This is simply the path. It is set to the
name of the C<tmp> directory and the name of the C<table>.
=cut
has fifo => (
is => 'ro' ,
isa => 'Str' ,
required => 1 ,
lazy => 1 ,
default => sub { $_[0]->dir . "/" . $_[0]->table . ".txt" } ,
documentation => 'Location of the fifo' ,
metaclass => 'NoGetopt' ,
);
# ---------------------------------------------------------------------
# METHODS
# ---------------------------------------------------------------------
=head1 INTERNAL METHODS
Do not use these methods directly.
=head2 _mkfifo
Creates the FIFO at C<[tmp]/mysqlslurp/[table].txt>. This will die if
a pipe, file, directory exists with the same descriptor.
The fifo is created as with default mode 0777.
=cut
sub _mkfifo {
print "Making FIFO ... " . $_[0]->fifo . "\n" if ( $_[0]->verbose );
unlink( $_[0]->fifo ) if ( -p $_[0]->fifo and $_[0]->force );
croak( "A FIFO already exists for that table. Delete with 'rm -f "
. $_[0]->fifo . "' before proceeding\n" ) if ( -e $_[0]->fifo );
( run in 2.135 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )