From: Yuval Kogman Date: Thu, 31 Jul 2008 23:23:23 +0000 (+0000) Subject: EvalWrap component X-Git-Tag: v0.900201~65 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dc58fe2554a0b9f7932212184eaf2d8a6ddef37;p=dbsrgits%2FDBIx-Class-Journal.git EvalWrap component --- diff --git a/lib/DBIx/Class/Journal/EvalWrap.pm b/lib/DBIx/Class/Journal/EvalWrap.pm new file mode 100644 index 0000000..2ed9cb4 --- /dev/null +++ b/lib/DBIx/Class/Journal/EvalWrap.pm @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +package DBIx::Class::Journal::EvalWrap; +use base qw(DBIx::Class::Journal); + +use strict; +use warnings; + +foreach my $method qw(journal_log_update journal_log_insert journal_log_delete) { + local $@; + eval "sub $method " . ' { + my ( $self, @args ) = @_; + local $@; + eval { $self->next::method(@args) }; + warn $@ if $@; + }; 1' || warn $@; +} + +__PACKAGE__ + +__END__ + +=pod + +=head1 NAME + +DBIx::Class::Journal::EvalWrap - Wrap all journal ops with an eval { } + +=head1 SYNOPSIS + + __PACKAGE__->journal_component("Journal::EvalWrap"); + +=head1 DESCRIPTION + +This component is a wrapper for the row methods in L that +aides in retrofitting a schema for journaling, by wrapping all the journal CRUD +operations with a Cmk_classdata('journal_deploy_on_connect'); __PACKAGE__->mk_classdata('journal_sources'); ## [ source names ] __PACKAGE__->mk_classdata('journal_user'); ## [ class, field for user id ] __PACKAGE__->mk_classdata('_journal_schema'); ## schema object for journal +__PACKAGE__->mk_classdata('journal_component'); __PACKAGE__->mk_classdata('journal_nested_changesets'); use strict; @@ -59,6 +60,7 @@ sub connection $self->_journal_schema($journal_schema); + my $comp = $self->journal_component || "Journal"; ## Create auditlog+history per table my %j_sources = map { $_ => 1 } $self->journal_sources @@ -69,7 +71,7 @@ sub connection { next unless($j_sources{$s_name}); $self->create_journal_for($s_name); - $self->class($s_name)->load_components('Journal'); + $self->class($s_name)->load_components($comp); # print STDERR "$s_name :", $self->class($s_name), "\n"; } diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index ff49a97..ecf87c8 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -5,6 +5,8 @@ use base qw/DBIx::Class::Schema/; __PACKAGE__->load_components(qw/+DBIx::Class::Schema::Journal/); +__PACKAGE__->journal_component("Journal::EvalWrap"); + no warnings qw/qw/; DBICTest::Schema->load_classes( qw/