From: Peter Rabbitson Date: Fri, 27 Apr 2012 07:00:42 +0000 (+0200) Subject: Use the now pure-perlized Devel::GlobalDestroy module X-Git-Tag: v0.08197~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6b39e463d43250ea171fa983b2364227172266f;p=dbsrgits%2FDBIx-Class.git Use the now pure-perlized Devel::GlobalDestroy module --- diff --git a/Makefile.PL b/Makefile.PL index 77abec6..90ac332 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -61,6 +61,7 @@ my $runtime_requires = { 'Context::Preserve' => '0.01', 'Data::Dumper::Concise' => '2.020', 'Data::Page' => '2.00', + 'Devel::GlobalDestruction' => '0', 'Hash::Merge' => '0.12', 'Moo' => '0.009014', 'MRO::Compat' => '0.09', diff --git a/lib/DBIx/Class/GlobalDestruction.pm b/lib/DBIx/Class/GlobalDestruction.pm deleted file mode 100644 index 33a9654..0000000 --- a/lib/DBIx/Class/GlobalDestruction.pm +++ /dev/null @@ -1,64 +0,0 @@ -# This is just a concept-test. If works as intended will ship in its own -# right as Devel::GlobalDestruction::PP or perhaps even as part of rafls -# D::GD itself - -package # hide from pause - DBIx::Class::GlobalDestruction; - -use strict; -use warnings; - -use base 'Exporter'; -our @EXPORT = 'in_global_destruction'; - -use DBIx::Class::Exception; - -if (defined ${^GLOBAL_PHASE}) { - eval 'sub in_global_destruction () { ${^GLOBAL_PHASE} eq q[DESTRUCT] }'; -} -elsif (eval { require Devel::GlobalDestruction }) { # use the XS version if available - *in_global_destruction = \&Devel::GlobalDestruction::in_global_destruction; -} -else { - my ($in_global_destruction, $before_is_installed); - - eval <<'PP_IGD'; - -sub in_global_destruction () { $in_global_destruction } - -END { - # SpeedyCGI runs END blocks every cycle but keeps object instances - # hence we have to disable the globaldestroy hatch, and rely on the - # eval traps (which appears to work, but are risky done so late) - $in_global_destruction = 1 unless $CGI::SpeedyCGI::i_am_speedy; -} - -# threads do not execute the global ENDs (it would be stupid). However -# one can register a new END via simple string eval within a thread, and -# achieve the same result. A logical place to do this would be CLONE, which -# is claimed to run in the context of the new thread. However this does -# not really seem to be the case - any END evaled in a CLONE is ignored :( -# Hence blatantly hooking threads::create -if ($INC{'threads.pm'}) { - require Class::Method::Modifiers; - Class::Method::Modifiers::install_modifier( threads => before => create => sub { - my $orig_target_cref = $_[1]; - $_[1] = sub { - { local $@; eval 'END { $in_global_destruction = 1 }' } - $orig_target_cref->(); - }; - }); - $before_is_installed = 1; -} - -# just in case threads got loaded after DBIC (silly) -sub CLONE { - DBIx::Class::Exception->throw("You must load the 'threads' module before @{[ __PACKAGE__ ]}") - unless $before_is_installed; -} - -PP_IGD - -} - -1; diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index f45ea2f..818341b 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -10,7 +10,7 @@ use DBIx::Class::ResultSourceHandle; use DBIx::Class::Exception; use DBIx::Class::Carp; -use DBIx::Class::GlobalDestruction; +use Devel::GlobalDestruction; use Try::Tiny; use List::Util 'first'; use Scalar::Util qw/blessed weaken isweak/; diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index dbe4cbe..049c626 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -9,7 +9,7 @@ use Try::Tiny; use Scalar::Util qw/weaken blessed/; use Sub::Name 'subname'; use B 'svref_2object'; -use DBIx::Class::GlobalDestruction; +use Devel::GlobalDestruction; use namespace::clean; use base qw/DBIx::Class/; diff --git a/t/53lean_startup.t b/t/53lean_startup.t index 30f1d90..6c00ff6 100644 --- a/t/53lean_startup.t +++ b/t/53lean_startup.t @@ -40,6 +40,7 @@ BEGIN { B locale + Devel::GlobalDestruction namespace::clean Try::Tiny Context::Preserve diff --git a/t/55namespaces_cleaned.t b/t/55namespaces_cleaned.t index 2205ded..aa6fca0 100644 --- a/t/55namespaces_cleaned.t +++ b/t/55namespaces_cleaned.t @@ -80,9 +80,6 @@ my $skip_idx = { map { $_ => 1 } ( # from the parent 'DBIx::Class::ResultSet::Pager', - # this is not part of the inheritance tree (plus is a temporary fix anyway) - 'DBIx::Class::GlobalDestruction', - # Moo does not name its generated methods, fix pending 'DBIx::Class::Storage::BlockRunner', ) };