diff options
author | Tony Cook <tony@develop-help.com> | 2022-07-25 14:53:39 +1000 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2022-11-08 10:12:46 +1100 |
commit | 42d0708bf6b7cda46f639a0d8517e24f28dc06f1 (patch) | |
tree | 26fb1939947772ca52d05b19476c8bc2d817d114 /dist | |
parent | 545d49904504b40413906fbf113de96011815266 (diff) | |
download | perl-42d0708bf6b7cda46f639a0d8517e24f28dc06f1.tar.gz |
make store_hook() handle regular expression objects
Previously this would complain it didn't know the object type
when preparing to call STORABLE_freeze.
Diffstat (limited to 'dist')
-rw-r--r-- | dist/Storable/Storable.xs | 1 | ||||
-rw-r--r-- | dist/Storable/t/blessed.t | 31 |
2 files changed, 31 insertions, 1 deletions
diff --git a/dist/Storable/Storable.xs b/dist/Storable/Storable.xs index 67ebba8afb..29f53b5ff2 100644 --- a/dist/Storable/Storable.xs +++ b/dist/Storable/Storable.xs @@ -3595,6 +3595,7 @@ static int store_hook( switch (type) { case svis_REF: case svis_SCALAR: + case svis_REGEXP: obj_type = SHT_SCALAR; break; case svis_ARRAY: diff --git a/dist/Storable/t/blessed.t b/dist/Storable/t/blessed.t index 398f21f80e..dea569b2b0 100644 --- a/dist/Storable/t/blessed.t +++ b/dist/Storable/t/blessed.t @@ -44,7 +44,7 @@ use Storable qw(freeze thaw store retrieve fd_retrieve); 'long VSTRING' => \(my $lvstring = eval "v" . 0 x 300), LVALUE => \(my $substr = substr((my $str = "foo"), 0, 3))); -my $test = 14; +my $test = 18; my $tests = $test + 41 + (2 * 6 * keys %::immortals) + (3 * keys %::weird_refs); plan(tests => $tests); @@ -436,3 +436,32 @@ is(ref $t, 'STRESS_THE_STACK'); like($msg, qr/Unexpected object type \(GLOB\) of class 'GlobHooked' in store_hook\(\) calling GlobHookedBase::STORABLE_freeze/, "check we get the verbose message"); } + +SKIP: +{ + $] < 5.012 + and skip "Can't assign regexps directly before 5.12", 4; + my $hook_called; + # store regexp via hook + { + package RegexpHooked; + sub STORABLE_freeze { + ++$hook_called; + "$_[0]"; + } + sub STORABLE_thaw { + my ($obj, $cloning, $serialized) = @_; + ++$hook_called; + $$obj = ${ qr/$serialized/ }; + } + } + + my $obj = bless qr/abc/, "RegexpHooked"; + my $data = freeze($obj); + ok($data, "froze regexp blessed into hooked class"); + ok($hook_called, "and the hook was actually called"); + $hook_called = 0; + my $obj_thawed = thaw($data); + ok($hook_called, "hook called for thaw"); + like("abc", $obj_thawed, "check the regexp"); +} |