Advertisement
happy-barney

Tie::No_Ref_Hash

Dec 30th, 2024
1,137
0
7 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.66 KB | None | 0 0
  1. package Tie::No_Ref_Hash;
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. our $VERSION = v1.0;
  7.  
  8. use parent qw (Tie::Hash);
  9.  
  10. sub prohibit_ref ($key) {
  11.     die q (Attempt to use reference as a key)
  12.         if ref $key;
  13. }
  14.  
  15. sub TIEHASH {
  16.     my ($class) = @_;
  17.  
  18.     bless { }, $class;
  19. }
  20.  
  21. sub FETCH {
  22.     my ($self, $key) = @_;
  23.  
  24.     prohibit_ref ($key);
  25.  
  26.     return $self->{$key};
  27. }
  28.  
  29. sub STORE {
  30.     my ($self, $key, $value) = @_;
  31.  
  32.     prohibit_ref ($key);
  33.  
  34.     return $self->{$key} = $v;
  35. }
  36.  
  37. sub DELETE {
  38.     my ($self, $key) = @_;
  39.  
  40.     prohibit_ref ($key);
  41.  
  42.     return delete $self->{$key};
  43. }
  44.  
  45. sub EXISTS {
  46.     my ($self, $key) = @_;
  47.  
  48.     prohibit_ref ($key);
  49.  
  50.     return exists $self->{$key};
  51. }
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement