The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Fun - access database stored procedures as methods

SYNOPSIS

    use DBI;
    use DBIx::Fun;
    
    my $dbh = DBI->connect('dbi:Oracle:orcl', 'scott', 'tiger');
    
    my $fun = DBIx::Fun->context($dbh);
    
    # print 5 random numbers from the database
    
    $fun->dbms_random->initialize( 123 );
    
    for my $i ( 1 .. 5 ) {
        printf "%d %d\n", $i, $fun->dbms_random->random;
    }
    
    $fun->dbms_random->terminate;
    
    $dbh->disconnect;

DESCRIPTION

This module allow Perl programs to access database stored procedures as if they were methods on an object.

CONSTRUCTORS

context( $dbh )

Creates a DBI::Fun subclass matching the driver of $dbh, e.g., DBD::Oracle => DBIx::Fun::Oracle.

    # call as a class method
    my $fun = DBIx::Fun->context($dbh);

Privately used as an object method to create child contexts.

fun( $dbh )

Returns a context for $dbh, cached in $dbh. Exportable as a function.

   use DBIx::Fun 'fun';

   print fun($dbh)->sysdate, "\n";
   sleep 60;

   # function signature cached in $dbh 
   print fun($dbh)->sysdate, "\n";

auto

Not an actual function. Importing 'auto' will load fun() into the DBI::db package, exposing it as a method on database handles.

   use DBIx::Fun 'auto';

   print $dbh->fun->sysdate, "\n";

METHODS

dbh

Accessor for the underlying database handle.

commit, rollback, disconnect

Convenience methods on the underlying database handle.

PRIVATE METHODS

_call($name, [ @args ] )

Call stored proc $name with arguments @args.

$fun->_call() can be used to call a stored procedure that contains characters not allowed in a Perl identifier, or that clashes with a method defined in Perl.