Alzabo

 view release on metacpan or  search on metacpan

inc/Alzabo/Build.pm  view on Meta::CPAN

use File::Spec;

sub ACTION_docs
{
    my $self = shift;

    $self->depends_on('code');

    $self->ACTION_pod_merge;

    $self->SUPER::ACTION_docs(@_);
}

sub ACTION_pod_merge
{
    my $self = shift;

    my $script = File::Spec->catfile( 'install_helpers', 'pod_merge.pl' );

    my $blib = File::Spec->catdir( qw( blib lib ) );
    $self->run_perl_script( $script, '', "lib $blib" );
}

sub ACTION_install
{
    my $self = shift;

    $self->SUPER::ACTION_install(@_);
}

1;

lib/Alzabo/Driver/MySQL.pm  view on Meta::CPAN

{
    # This will cause an auto_increment column to go up (because we're
    # inserting a NULL into it).
    return undef;
}

sub rollback
{
    my $self = shift;

    eval { $self->SUPER::rollback };

    if ( my $e = $@ )
    {
        unless ( $e->error =~ /Some non-transactional changed tables/ )
        {
            if ( Alzabo::Utils::safe_can( $e, 'rethrow' ) )
            {
                $e->rethrow;
            }
            else

lib/Alzabo/Driver/PostgreSQL.pm  view on Meta::CPAN

    return @schemas;

}

sub tables
{
    my $self = shift;

    # It seems that with DBD::Pg 1.31 & 1.32 you can't just the
    # database's table, you also get the system tables back
    return grep { ! /^(?:pg_catalog|information_schema)\./ } $self->SUPER::tables( @_ );
}

sub create_database
{
    my $self = shift;

    # Obviously we can't connect to the main database if it doesn't
    # exist yet, but postgres doesn't let us be databaseless, so we
    # connect to something else.  "template1" should always be there.
    my $dbh = $self->_make_dbh( @_, name => 'template1' );

lib/Alzabo/MethodMaker.pm  view on Meta::CPAN

}

sub make_insert_hooks
{
    my $self = shift;

    my $code = '';
    $code .= "        return \$s->schema->run_in_transaction( sub {\n";
    $code .= "            my \$new;\n";
    $code .= "            \$s->pre_insert(\\\%p);\n" if $self->{table_class}->can('pre_insert');
    $code .= "            \$new = \$s->SUPER::insert(\%p);\n";
    $code .= "            \$s->post_insert({\%p, row => \$new});\n" if $self->{table_class}->can('post_insert');
    $code .= "            return \$new;\n";
    $code .= "        } );\n";

    eval <<"EOF";
{
    package $self->{table_class};
    sub insert
    {
        my \$s = shift;

lib/Alzabo/MethodMaker.pm  view on Meta::CPAN

    return $hooks;
}

sub make_update_hooks
{
    my $self = shift;

    my $code = '';
    $code .= "        \$s->schema->run_in_transaction( sub {\n";
    $code .= "            \$s->pre_update(\\\%p);\n" if $self->{row_class}->can('pre_update');
    $code .= "            \$s->SUPER::update(\%p);\n";
    $code .= "            \$s->post_update(\\\%p);\n" if $self->{row_class}->can('post_update');
    $code .= "        } );\n";

    eval <<"EOF";
{
    package $self->{row_class};

    sub update
    {
        my \$s = shift;

lib/Alzabo/MethodMaker.pm  view on Meta::CPAN


        return \$s->schema->run_in_transaction( sub {

$pre

            my \@r;
            my %r;

            if (wantarray)
            {
                \@r{ \@cols } = \$s->SUPER::select(\@cols);
            }
            else
            {
                \$r{ \$cols[0] } = (scalar \$s->SUPER::select(\$cols[0]));
            }
$post
            return wantarray ? \@r{\@cols} : \$r{ \$cols[0] };
        } );
    }

    sub select_hash
    {
        my \$s = shift;
        my \@cols = \@_;

        return \$s->schema->run_in_transaction( sub {

$pre

            my \%r = \$s->SUPER::select_hash(\@cols);

$post

            return \%r;
        } );
    }
}
EOF

    Alzabo::Exception::Eval->throw( error => $@ ) if $@;

lib/Alzabo/MethodMaker.pm  view on Meta::CPAN

          ) );
}

sub make_delete_hooks
{
    my $self = shift;

    my $code = '';
    $code .= "        \$s->schema->run_in_transaction( sub {\n";
    $code .= "            \$s->pre_delete(\\\%p);\n" if $self->{row_class}->can('pre_delete');
    $code .= "            \$s->SUPER::delete(\%p);\n";
    $code .= "            \$s->post_delete(\\\%p);\n" if $self->{row_class}->can('post_delete');
    $code .= "        } );\n";

    eval <<"EOF";
package $self->{row_class};

sub delete
{
    my \$s = shift;
    my \%p = \@_;

lib/Alzabo/RDBMSRules/PostgreSQL.pm  view on Meta::CPAN

sub quote_identifiers_character { '"' }

sub schema_sql
{
    my $self = shift;

    validate_pos( @_, { isa => 'Alzabo::Schema' } );

    my $schema = shift;

    my @sql = $self->SUPER::schema_sql($schema);

    # This has to come at the end because we don't know which tables
    # reference other tables.
    foreach my $t ( $schema->tables )
    {
        foreach my $con ( grep { /\s*(?:check|constraint)/i } $t->attributes )
        {
            push @sql, $self->table_constraint_sql($t);
        }

lib/Alzabo/RDBMSRules/PostgreSQL.pm  view on Meta::CPAN

    if ($is_recreate)
    {
        # We need to drop foreign keys referring to this table before
        # we drop it.
        foreach my $fk ( $table->all_foreign_keys )
        {
            push @sql, $self->drop_foreign_key_sql( $fk->reverse );
        }
    }

    push @sql, $self->SUPER::drop_table_sql($table);

    unless ($is_recreate)
    {
        foreach my $c ( $table->columns )
        {
            push @sql, $self->_drop_sequence_sql($c) if $c->sequenced;
        }
    }

    return @sql;

lib/Alzabo/Runtime/RowState/InCache.pm  view on Meta::CPAN


use strict;

use base qw(Alzabo::Runtime::RowState::Live);

BEGIN
{
    no strict 'refs';
    foreach my $meth ( qw( select select_hash ) )
    {
        my $super = "SUPER::$meth";
        *{__PACKAGE__ . "::$meth"} =
            sub { my $s = shift;

                  $s->refresh(@_) unless $s->_in_cache(@_);

                  $s->$super(@_);
              };
    }
}

sub update
{
    my $class = shift;
    my $row = shift;

    my $old_id = $row->id_as_string;

    $class->refresh($row) unless $class->_in_cache($row);

    my $changed = $class->SUPER::update( $row, @_ );

    return $changed if exists $row->{id_string};

    Alzabo::Runtime::UniqueRowCache->delete_from_cache( $row->table->name, $old_id );

    Alzabo::Runtime::UniqueRowCache->write_to_cache($row);

    return $changed;
}

sub delete
{
    my $class = shift;
    my $row = shift;

    my $old_id = $row->id_as_string;

    $class->SUPER::delete( $row, @_ );

    Alzabo::Runtime::UniqueRowCache->delete_from_cache( $row->table->name, $old_id );
}

sub refresh
{
    my $class = shift;

    $class->SUPER::refresh(@_);

#    return if $class->_in_cache($row); #????
}

sub _in_cache
{
    return
        Alzabo::Runtime::UniqueRowCache->row_in_cache
            ( $_[1]->table->name, $_[1]->id_as_string );
}

lib/Alzabo/Runtime/Table.pm  view on Meta::CPAN

# needed.
#
sub column
{
    my $self = shift;

    # I'm an alias, make an alias column
    if ( $self->{alias_name} )
    {
        my $name = shift;
        my $col = $self->SUPER::column($name);

        # not previously cloned
        unless ( $col->table eq $self )
        {
            # replace our copy of this column with a clone
            $col = $col->alias_clone( table => $self );
            my $index = $self->{columns}->Indices($name);
            $self->{columns}->Replace( $index, $col, $name );

            Scalar::Util::weaken( $col->{table} );

            delete $self->{pk_array} if $col->is_primary_key;
        }

        return $col;
    }
    else
    {
        return $self->SUPER::column(@_);
    }
}

sub alias_name
{
    # intentionally don't call $_[0]->name for a noticeable
    # performance boost
    return $_[0]->{alias_name} || $_[0]->{name};
}

sub real_table
{
    return $_[0]->{real_table} || $_[0];
}

# This gets called a _lot_ so doing this sort of 'memoization' helps
sub primary_key
{
    my $self = shift;

    $self->{pk_array} ||= [ $self->SUPER::primary_key ];

    return ( wantarray ?
             @{ $self->{pk_array} } :
             $self->{pk_array}->[0]
           );
}

1;

__END__

lib/Alzabo/SQLMaker/MySQL.pm  view on Meta::CPAN

		 Alzabo::Utils::safe_isa( $_[ $i + 1 ], 'Alzabo::SQLMaker::Function' ) &&
		 $_[ $i + 1 ]->as_string( $self->{driver}, $self->{quote_identifiers} ) =~
                 /^\s*IN BOOLEAN MODE/i )
	    {
		$_[$i] .= ' ' . $_[$i + 1]->as_string( $self->{driver}, $self->{quote_identifiers} );
		splice @_, $i + 1, 1;
	    }
	}
    }

    $self->SUPER::select(@_);
}

sub condition
{
    my $self = shift;

    #
    # Special check for [ MATCH( $foo_col, $bar_col ), AGAINST('foo bar') ]
    # IN_BOOLEAN_MODE is optional
    #
    if ( Alzabo::Utils::safe_isa( $_[0], 'Alzabo::SQLMaker::Function' ) &&
	 $_[0]->as_string( $self->{driver}, $self->{quote_identifiers} ) =~ /^\s*MATCH/i )
    {
	$self->{last_op} = 'condition';
	$self->{sql} .=
            join ' ', map { $_->as_string( $self->{driver}, $self->{quote_identifiers} ) } @_;
    }
    else
    {
	$self->SUPER::condition(@_);
    }
}

sub limit
{
    my $self = shift;
    my ($max, $offset) = @_;

    $self->_assert_last_op( qw( from function where and or condition order_by group_by ) );

lib/Alzabo/SQLMaker/PostgreSQL.pm  view on Meta::CPAN

    $MADE_FUNCTIONS = 1;
}

sub init
{
    1;
}

sub new
{
    my $self = shift->SUPER::new(@_);

    $self->{alias_in_having} = 0;

    return $self;
}

sub limit
{
    my $self = shift;
    my ($max, $offset) = @_;



( run in 1.096 second using v1.01-cache-2.11-cpan-49f99fa48dc )