BingoX
view release on metacpan or search on metacpan
lib/BingoX/Carbon.pm view on Meta::CPAN
=cut
package BingoX::Carbon;
use DBI;
use Carp qw(:DEFAULT cluck);
use strict;
use Date::Parse;
use BingoX::Time;
use vars qw($AUTOLOAD $debug);
BEGIN {
$BingoX::Carbon::REVISION = (qw$Revision: 2.36 $)[-1];
$BingoX::Carbon::VERSION = '1.92';
$debug = undef;
if ($debug) {
require Data::Dumper;
}
}
=item C<import> ( )
Called from 'use BingoX::Carbon;'
Possible arguments are as follows:
=back
=over 4
=item * :cache_all
flag will put all data into the object at time of construction.
The default action is to store only primary_keys in the object
until data is needed, but this approach proved very inefficient
in certain situations.
=item * :no_dynmeth
flag will stop the creation of methods in calling class for all
the elements of the class' fieldorder.
=item * :full_dynmeth
flag will avoid using 'forwarder' methods and instead use full
dynamic methods - each with it's own code resembling AUTOLOAD.
By default, forwarder methods are used and all call
_old_school_autoload
Any other element, not starting with the ':' character will be interpreted
as a method name with which to create an access method in the calling class.
=back
=cut
sub import {
my $self = shift;
my $myclass = ref($self) || $self;
my $class = (caller)[0];
my @args = @_;
warn "BingoX::Carbon: import: class=$class: @args myclass=$myclass" if ($debug);
## Initialize special content and date field methods
no strict 'refs';
@{"${class}::ISA"} = ( __PACKAGE__ ) unless ($class->isa( __PACKAGE__ ));
BingoX::Carbon::_content_meth_init( $class );
BingoX::Carbon::_date_meth_init( $class );
my $no_dynmeth = 0;
my $full_dynmeth = 0;
## BingoX::Carbon methods are called as functions, passing $class (caller[0]). ##
## This is needed because import is called before the $class @ISA is set. ##
## Therefore, calling $class->method wouldn't work because $class doesn't inherit ##
## from anything yet! ##
my @fields = ( );
foreach (@args) {
if (substr($_, 0, 1) eq ':') {
if ($_ eq ':cache_all') {
$BingoX::Carbon::cache_all{ $class }++;
} elsif ($_ eq ':full_dynmeth') {
$full_dynmeth = 1;
} elsif ($_ eq ':no_dynmeth') {
$no_dynmeth = 1;
&BingoX::Carbon::_create_access_method( $class, 'AUTOLOAD' );
}
} else {
warn "explicitly creating method $_ in class $class" if ($debug);
# &BingoX::Carbon::_create_access_method( $class, $_ );
# &BingoX::Carbon::_create_forwarder_method( $class, $_ );
push(@fields, $_);
}
} # END foreach block
push(@fields, @{ &BingoX::Carbon::fieldorder( $class ) || [] }) unless ($no_dynmeth);
foreach my $name (@fields) {
if ($full_dynmeth) {
&BingoX::Carbon::_create_access_method( $class, $name );
} else {
&BingoX::Carbon::_create_forwarder_method( $class, $name );
}
}
} # END sub import
=over 4
=item C<new> ( [ $dbh, ] \%data )
Constructs a new object with the data in the hashref passed to it.
You must supply a value for all primary key columns, unless the database
provides a method for autogenerating this value. If an ID isn't specified
the ID will be the next number in the database sequence :
Sybase
Class data $identity contains name of column which is a Sybase IDENTITY.
The IDENTITY field will be omitted from the insert statement so Sybase can autogenerate it.
New will then select @@identity to retreive the result of triggering IDENTITY.
( run in 2.944 seconds using v1.01-cache-2.11-cpan-364913b4093 )