App-Dochazka-REST
view release on metacpan or search on metacpan
lib/App/Dochazka/REST.pm view on Meta::CPAN
=item * Data model
=back
In a nutshell, clients attempt to translate user intent into REST API
calls, which are transmitted over a network (using the HTTP protocol) to
the server. The server processes incoming HTTP requests. Requests for
valid REST resources are passed to the API for processing and errors are
generated for invalid requests. The result is returned to the client in
an HTTP response. The REST API uses the PostgreSQL server to save state.
The clients and the REST API use the data model to represent and manipulate
objects.
=head1 DOCUMENTATION
=over
=item * L<App::Dochazka::REST::Guide>
A detailed guide to the REST server.
=item * L<App::Dochazka::REST::Docs::Resources>
Dochazka REST API documentation.
=item * L<App::Dochazka::Common>
Dochazka data model and other bits used by all Dochazka components.
=item * L<App::Dochazka::CLI> and L<App::Dochazka::CLI::Guide>
Reference Dochazka command-line client.
=item * L<App::Dochazka::WWW>
Reference Dochazka WWW client.
=over
=head1 EXPORTS
=cut
use Exporter qw( import );
our @EXPORT_OK = qw( init_arbitrary_script $faux_context );
our $faux_context;
=head1 FUNCTIONS
=head2 run_sql
Takes a L<DBIx::Connector> object and an array of SQL statements. Runs them
one by one until an exception is thrown or the last statement completes
successfully. Returns a status object which will be either OK or ERR.
If NOT_OK, the error text will be in C<< $status->text >>.
=cut
sub run_sql {
my ( $conn, @stmts ) = @_;
my $status;
try {
foreach my $stmt ( @stmts ) {
$log->debug( "Running SQL statement $stmt" );
$conn->run( fixup => sub { $_->do( $stmt ); } );
}
} catch {
$status = $CELL->status_err( 'DOCHAZKA_DBI_ERR', args => [ $_ ] );
};
return $status if $status;
return $CELL->status_ok;
}
sub _do_audit_triggers {
my ( $mode, $conn ) = @_;
my $sql;
if ( $mode eq 'create' ) {
$sql = $site->DBINIT_CREATE_AUDIT_TRIGGERS;
} elsif ( $mode eq 'delete' ) {
$sql = $site->DBINIT_DELETE_AUDIT_TRIGGERS;
} else {
die "AAADFDGGGGGGAAAAAAAHHH! " . __PACKAGE__ . "::_do_audit_triggers";
}
my @prepped_sql;
foreach my $table ( @{ $site->DOCHAZKA_AUDIT_TABLES } ) {
my $sql_copy = $sql;
my $question_mark = quotemeta('?');
$log->debug( "Replacing question mark with $table" );
$sql_copy =~ s{$question_mark}{$table};
push( @prepped_sql, $sql_copy );
}
my $status = run_sql(
$conn,
@prepped_sql,
);
return $status;
}
=head2 create_audit_triggers
Create the audit triggers. Wrapper for _do_audit_triggers
=cut
sub create_audit_triggers {
my $conn = shift;
return _do_audit_triggers( 'create', $conn );
}
( run in 0.591 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )