DBomb

 view release on metacpan or  search on metacpan

DBomb/Base.pm  view on Meta::CPAN

# $class->select_count()
sub select_count
{
    my $class = ref($_[0]) ? ref(shift) : shift;
    return new DBomb::Query($class->_dbo_dbh,["COUNT(*)"])->from($class->_dbo_table_info->name);
}


## $class->selectall_arrayref()
## $class->selectall_arrayref(@bind_values)
## $class->selectall_arrayref($dbh, @bind_values)
sub selectall_arrayref
{
    my ($class, @bind_values) = @_;
    my $dbh;

    $dbh = shift(@bind_values) if UNIVERSAL::isa($bind_values[0],'DBI::db');

    # Let $dbh override default dbh
    $dbh = $class->_dbo_dbh unless defined $dbh;

    $class = ref($class) if ref($class);

    ## We don't need a glued query here since we are just selecting the primary key columns.
    ## The tied list will create the objects as needed.
    my $query = new DBomb::Query($dbh,$class->_dbo_table_info->primary_key->column_names)
                        ->from($class->_dbo_table_info->name);
    my $keys_list = $query->selectall_arrayref;
    my @arr;
    tie @arr, 'DBomb::Tie::PrimaryKeyList', $class, $keys_list;
    return \@arr;
}

## delete()
## $class->delete()
sub delete
{
    my $self = shift;
        assert(@_==0, 'delete takes no arguments');

    if (ref $self){
        $self->_dbo_delete(@_);
    }
    else{
        $self->_dbo_delete_static(@_);
    }
}


sub insert
{
    my $self = shift;
    if (ref $self){
        $self->_dbo_insert(@_);
    }
    else{
        $self->_dbo_insert_static(@_);
    }
}

sub update
{
    my $self = shift;
    if (ref $self){
        $self->_dbo_update(@_);
    }
    else{
        $self->_dbo_update_static(@_);
    }
}

sub copy_shallow
{
    my $self = shift;
        assert(ref($self) && UNIVERSAL::isa($self,__PACKAGE__), "copy_shallow requires an object instance");

    my $id = $self->_dbo_copy_shallow(@_);
    if (defined $id){
        return ref($self)->new($id);
    }
    undef
}

sub dbo_is_bound
{
    my $self = shift;
    $self->_dbo_is_bound;
}

1;
__END__



( run in 1.857 second using v1.01-cache-2.11-cpan-39bf76dae61 )