Acme-BeyondPerl-ToSQL
view release on metacpan or search on metacpan
lib/Acme/BeyondPerl/ToSQL.pm view on Meta::CPAN
package Acme::BeyondPerl::ToSQL;
use strict;
use DBI;
use Carp;
our $VERSION = 0.01;
our $DEBUG = 0;
my $Dbh; # database handle
my $Type; # rdbm type
END {
$Dbh->disconnect()
}
##############################################################################
sub import {
my $class = shift;
my %hash = %{ $_[0] } if(@_ == 1);
my ($dsn, $user, $pass, $opt) = (@_ > 1) ? @_ : @{$hash{dbi}};
_connect($dsn, $user, $pass, $opt) unless($Dbh);
_overload();
overload::constant (
integer => \&_integer_handler,
float => \&_float_handler,
);
if(defined $hash{debug}){ $DEBUG = $hash{debug}; }
}
my $OPs = {
'+' => sub { shift->add(@_) },
'-' => sub { shift->sub(@_) },
'*' => sub { shift->mul(@_) },
'/' => sub { shift->div(@_) },
'%' => sub { shift->mod(@_) },
'**' => sub { shift->pow(@_) },
'log' => sub { shift->log(@_) },
'sqrt' => sub { shift->sqrt(@_)},
'abs' => sub { shift->abs(@_) },
'cos' => sub { shift->cos(@_) },
'sin' => sub { shift->sin(@_) },
'exp' => sub { shift->exp(@_) },
'atan2'=> sub { shift->atan2(@_) },
'<<' => sub { shift->lshift(@_) },
'>>' => sub { shift->rshift(@_) },
'&' => sub { shift->and(@_) },
'|' => sub { shift->or(@_) },
'^' => sub { shift->xor(@_) },
};
sub ops { return $OPs; }
sub Type { $Type; }
##############################################################################
sub _connect {
my ($dsn, $user, $pass, $opts) = @_;
$Dbh = DBI->connect($dsn, $user, $pass, $opts) or die $!;
( run in 1.074 second using v1.01-cache-2.11-cpan-f0fbb3f571b )