Class-DBI-ViewLoader
view release on metacpan or search on metacpan
_clear_dbi_handle
$obj->_clear_dbi_handle
This is the cleanup method for the object's DBI handle. It is called
whenever the DBI handle needs to be closed down. i.e. when a new handle
is used or the object goes out of scope. Subclasses should override this
method if they need to clean up any state data that relies on the
current database connection, like statement handles for example. If you
don't want the handle that the object is using to be disconnected, use
the _set_keepalive method.
sub _clear_dbi_handle {
my $self = shift;
delete $self->{statement_handle};
$self->SUPER::_clear_dbi_handle(@_);
}
_set_dbi_handle
$obj = $obj->_set_dbi_handle($dbh)
This method is used to attach a DBI handle to the object. It might prove
useful to use this method in order to use an existing database
connection in the loader object. Note that unlike set_dsn, calling this
method directly will not cause an appropriate driver to be loaded. See
_load_driver for that.
_set_keepalive
$obj = $obj->_set_keepalive($bool)
When set to true, the database handle used by the object won't be
disconnected automatically.
_load_driver
$obj = $obj->_load_driver($driver_name)
This method is used internally by set_dsn to load a driver to handle
database-specific functionality. It can be called directly in
conjunction with _set_dbi_handle to load views from an existing database
lib/Class/DBI/ViewLoader.pm view on Meta::CPAN
$self->_clear_dbi_handle;
$self->{_dbh} = $dbh;
return $self;
}
# disconnect current DBI handle, if any
sub _clear_dbi_handle {
my $self = shift;
return $self if $self->_keepalive;
if (defined $self->{_dbh}) {
delete($self->{_dbh})->disconnect;
}
return $self;
}
sub DESTROY {
my $self = shift;
$self->_clear_dbi_handle;
}
# switch to disable _clear_dbi_handle
sub _set_keepalive {
my $self = shift;
$self->{__keepalive} = shift;
return $self;
}
# check status of switch
sub _keepalive {
my $self = shift;
return $self->{__keepalive};
}
=head2 set_namespace
$obj = $obj->set_namespace($namespace)
Sets the namespace to load views into. This should be a valid perl package name,
with or without a trailing '::'.
=cut
lib/Class/DBI/ViewLoader.pm view on Meta::CPAN
=head2 _clear_dbi_handle
$obj->_clear_dbi_handle
This is the cleanup method for the object's DBI handle. It is called whenever
the DBI handle needs to be closed down. i.e. when a new handle is used or the
object goes out of scope. Subclasses should override this method if they need to
clean up any state data that relies on the current database connection, like
statement handles for example. If you don't want the handle that the object is
using to be disconnected, use the _set_keepalive method.
sub _clear_dbi_handle {
my $self = shift;
delete $self->{statement_handle};
$self->SUPER::_clear_dbi_handle(@_);
}
=head2 _set_dbi_handle
$obj = $obj->_set_dbi_handle($dbh)
This method is used to attach a DBI handle to the object. It might prove useful
to use this method in order to use an existing database connection in the loader
object. Note that unlike set_dsn, calling this method directly will not cause an
appropriate driver to be loaded. See _load_driver for that.
=head2 _set_keepalive
$obj = $obj->_set_keepalive($bool)
When set to true, the database handle used by the object won't be disconnected automatically.
=head2 _load_driver
$obj = $obj->_load_driver($driver_name)
This method is used internally by set_dsn to load a driver to handle
database-specific functionality. It can be called directly in conjunction with
_set_dbi_handle to load views from an existing database connection.
lib/Class/DBI/ViewLoader/Auto.pm view on Meta::CPAN
my $sub = $class->can('db_Main')
or croak "$class has no connection";
my $dbh = &$sub($class);
my $driver = $dbh->{'Driver'}->{'Name'};
return Class::DBI::ViewLoader->new(%opts)
->_load_driver($driver)
->_set_dbi_handle($dbh)
->_set_keepalive(1)
->add_left_base_classes($class)
->load_views;
}
1;
__END__
=head1 DIAGNOSTICS
( run in 2.183 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )