plugin to persist package changes persist-package
Graham Knop [Fri, 13 Jun 2014 12:40:22 +0000 (08:40 -0400)]
lib/Eval/WithLexicals/WithPackagePersistence.pm [new file with mode: 0644]

diff --git a/lib/Eval/WithLexicals/WithPackagePersistence.pm b/lib/Eval/WithLexicals/WithPackagePersistence.pm
new file mode 100644 (file)
index 0000000..ced7ddb
--- /dev/null
@@ -0,0 +1,32 @@
+package Eval::WithLexicals::WithPackagePersistence;
+use Moo::Role;
+use Sub::Quote;
+
+our $VERSION = '1.002000'; # 1.2.0
+$VERSION = eval $VERSION;
+
+around eval => sub {
+  my $orig = shift;
+  my($self) = @_;
+
+  local *Eval::WithLexicals::Cage::package;
+  my @ret = $orig->(@_);
+  $self->in_package(Eval::WithLexicals::Cage::package());
+  @ret;
+};
+
+around capture_code => sub {
+  my $orig = shift;
+  my($self) = @_;
+
+  return (
+    q{
+      sub Eval::WithLexicals::Cage::package {
+        __PACKAGE__;
+      }
+    },
+    $orig->(@_),
+  )
+};
+
+1;