Skip Menu |

This queue is for tickets about the Catalyst-Plugin-I18N-DBI CPAN distribution.

Report information
The Basics
Id: 52693
Status: resolved
Priority: 0/
Queue: Catalyst-Plugin-I18N-DBI

People
Owner: Nobody in particular
Requestors: rkitover@cpan.org (no email address)
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.2.2
Fixed in: (no value)



Subject: Does not used blessed context in fail_with closure
Patch attached, this fixes an issue with using the plugin in conjunction with Catalyst::TraitFor::Model:::DBIC::Schema::Caching .
Subject: i18n-dbi-capture-ctx.patch
diff --git a/Build.PL b/Build.PL index bf2ff70..cec3c86 100644 --- a/Build.PL +++ b/Build.PL @@ -16,6 +16,7 @@ my $builder = Module::Build->new( 'I18N::LangTags::Detect' => 0, 'Test::More' => 0, 'version' => 0, + 'Task::Weaken' => 0, }, add_to_cleanup => ['Catalyst-Plugin-I18N-DBI-*'], create_makefile_pl => 'traditional', diff --git a/Makefile.PL b/Makefile.PL index 1378b98..15f4842 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,7 +12,8 @@ WriteMakefile 'Locale::Maketext::Lexicon' => 0, 'NEXT' => 0, 'Test::More' => 0, - 'version' => 0 + 'version' => 0, + 'Task::Weaken' => 0, }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [] diff --git a/lib/Catalyst/Plugin/I18N/DBI.pm b/lib/Catalyst/Plugin/I18N/DBI.pm index a6fda37..6dd03d8 100644 --- a/lib/Catalyst/Plugin/I18N/DBI.pm +++ b/lib/Catalyst/Plugin/I18N/DBI.pm @@ -9,6 +9,7 @@ use DBI; use NEXT; use I18N::LangTags (); use I18N::LangTags::Detect; +use Scalar::Util (); use Locale::Maketext::Lexicon; @@ -190,6 +191,23 @@ sub setup { $c->NEXT::setup(@_); } +=head2 prepare + +=cut + +my $current_ctx; + +sub prepare { + my $app = shift; + + my $c = $app->NEXT::prepare(@_); + + $current_ctx = $c; + Scalar::Util::weaken $current_ctx; + + return $c; +} + sub _init_i18n { my $c = shift; @@ -236,9 +254,9 @@ sub _init_i18n { my ($flh, $key, @params) = @_; my $value; eval { - my $res = $c->model($cfg->{lex_class})->search({ key => $key, lang => $lang, lex => $default_lex })->first; + my $res = $current_ctx->model($cfg->{lex_class})->search({ key => $key, lang => $lang, lex => $default_lex })->first; unless ($res) { - my $rec = $c->model($cfg->{lex_class})->create( + my $rec = $current_ctx->model($cfg->{lex_class})->create( { lex => $default_lex, key => $key, @@ -251,7 +269,7 @@ sub _init_i18n { $value = $res->value; } }; - $c->log->error("Failed within fail_with(): $@") if $@; + $current_ctx->log->error("Failed within fail_with(): $@") if $@; return $value; }
Patch applied width v0.2.3
Patch applied width v0.2.3