Apache2-Controller

 view release on metacpan or  search on metacpan

README.txt  view on Meta::CPAN

Apache2-Controller

fast MVC-style Apache2 mod_perl2 handler app framework

Apache2::Controller organizes subclassed Apache2::Request handler objects in
an MVC module structure. A YAML file maps url paths to modules. $self is $r,
the subclassed XS APR bindings with libapreq methods to load query string,
etc. Stream with $r->print or use a parallel web tree of Template::Toolkit
files. Hook in any model class like DBIx::Class or direct SQL or sockets,
connections cached across requests. Session cookie plugin. Other great stuff.


INSTALLATION

To install this module, run the following commands:

	perl Makefile.PL

lib/Apache2/Controller/SQL/MySQL.pm  view on Meta::CPAN


=item data

The hash ref of field data to insert.

=item on_dup_sql

Optional string of SQL for after 'ON DUPLICATE KEY UPDATE'.
Format it yourself.

=item on_dup_bind

Array ref of bind values for extra C<?> characters in C<on_dup_sql>.

=back

=cut

use strict;
use warnings FATAL => 'all';
use English '-no_match_vars';
use Apache2::Controller::X;

sub insert_hash {
    my ($self, $p) = @_;

    my ($table, $data, $on_dup_sql, $on_dup_bind) = @{$p}{qw(
         table   data   on_dup_sql   on_dup_bind
    )};

    my @bind = values %{$data};

    my $sql 
        = "INSERT INTO $table SET\n"
        . join(",\n", map {"    $_ = ".(ref $_ ? $_ : '?')} keys %{$data});

    if ($on_dup_sql) {
        $sql .= "\nON DUPLICATE KEY UPDATE\n$on_dup_sql\n";
        push @bind, @{$on_dup_bind} if $on_dup_bind;
    }

    my $dbh = $self->{dbh};
    my $id;
    eval {
        DEBUG("preparing handle for sql:\n$sql\n---\n");
        my $sth = $dbh->prepare_cached($sql);
        $sth->execute(@bind);
        ($id) = $dbh->selectrow_array(q{ SELECT LAST_INSERT_ID() });
    };
    if ($EVAL_ERROR) {
        a2cx message => "database error: $EVAL_ERROR",
            dump => { sql => $sql, bind => \@bind, };
    }
    return $id;
}

=head1 SEE ALSO

L<Apache2::Controller::DBI::Connector>

L<Apache2::Controller>



( run in 0.797 second using v1.01-cache-2.11-cpan-2398b32b56e )