Store::Opaque(3pm)

πŸ’– Store::Opaque πŸ’– (User Contributed Perl Documentation, bestie)

okay so before we even start, the manual name is Store::Opaque(3pm) β€” it lives in the perl User Contributed Perl Documentation section, and it is unhinged in the best way because it solves a problem literally nobody thinks about until it bites them. πŸŽ€


✨ NAME ✨

Store::Opaque β€” objects that are opaque so nobody accidentally Dumps them or lets them pop up in a stack trace πŸ’…

like. it's giving privacy but for your own code, not for attackers. iykyk.


πŸ¦‹ SYNOPSIS πŸ¦‹

  package MyCreditCardInfo;
  use strict; use warnings;
  use Store::Opaque;
  our @ISA = qw(Store::Opaque);

  sub get_creditcard_number {
    $_[0]->_get("ccnumber")
  }

  sub set_creditcard_number {
    $_[0]->_set("ccnumber", $_[1])
  }

  1;
  # use this like any other object...

periodt. that's the whole vibe β€” subclass it, use it like any other object, and it just works.


🌸 DESCRIPTION 🌸

bestie, before you go any further, please actually internalize this: this module is not directly about security in the sense of preventing malicious action! it's about preventing mistakes that could turn out to be a security or compliance issue. πŸ™ˆ

so picture this. you've got code handling super sensitive data that should never end up in your logs:

  use Carp;
  foo("This does not belong in logs");
  sub foo {
    my $super_sensitive = shift;
    this_can_die();
  }
  sub this_can_die {
    Carp::confess("Gotcha"); # stack trace
  }

and if you're logging errors, this is what lands in your logs:

  Gotcha at /tmp/t.pl line 8
          main::this_can_die() called at /tmp/t.pl line 5
          main::foo('This does not belong in logs') called at /tmp/t.pl line 2

great, not! 😭 your secret is just... sitting there. in plaintext. in the log file. iconic in the worst possible way.

there's a whole bunch of techniques that fix this. the easiest one is literally just using hash-based objects to store the info and pass it around. in general you'd pass it around as some sort of reference to prevent this.

BUT. alas. that's easily defeated by accident if developers write stuff like this:

  sub foo {
    warn Data::Dumper->Dump(\@_); # FIXME just for debugging
    my $super_sensitive = shift;
    this_can_die();
  }

again, there's a myriad of ways to explicitly defeat that, but next i'd bring up the more powerful Data::Dump::Streamer (in conjunction with PadWalker and B::Deparse). even inside out objects can accidentally be dumped if you're using Data::Dump::Streamer to dump their methods. it's becoming progressively less easy to make a mistake like the above, but why bother? πŸ’…

this module implements an opaque object implementation that does not suffer from these issues. let me repeat that, because it matters: this isn't about hiding anything from an attacker. it's about preventing mistakes from people who have legitimate access. 🫢

oh, and don't use this for all of your objects, because it comes with a small memory and moderate performance overhead. it's a specialized little diva, not a foundation. πŸ‘‘

πŸ’€ WARNING πŸ’€

if you do not fully understand the previous section, look elsewhere and do not use this module. seriously. no cap. this is a "know what you're doing" kind of module, bestie.


πŸ”₯ METHODS AND USAGE πŸ”₯

you use this module by subclassing. if that doesn't work for you, you can manually import the methods in the class. and if you don't know how that works... you shouldn't be doing it. πŸ™ˆ

your subclass will inherit the following methods:

πŸŽ€ new

a simple constructor that takes no arguments. you can override it as follows:

  sub new {
    my $class = shift;
    my $self = $class->SUPER::new;
    # initialize here
    return $self;
  }

πŸŽ€ _set

the generic setter for the stored information:

  sub set_ccinfo {
    my $self = shift;
    my $value = shift;
    $self->_set("ccinfo", $value);
  }

where "ccinfo" is the key to store the $value under. and if this feels reminiscent of a hash β€” that's not coincidental, because the object is a hash under the hood. 🧚

you can use any string as a key that would otherwise work in a normal hash-based object.

πŸŽ€ _get

the generic accessor for the stored information. works just like _set without the $value. ⭐


πŸ‘‘ AUTHOR πŸ‘‘

Steffen Mueller, <smueller@cpan.org> πŸ’œ


Copyright (C) 2011 by Steffen Mueller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.


and that's the whole page, bestie!! 🫢 this was perl v5.42.3, dated 2026-08-19, served up fresh from Store::Opaque(3pm) β€” go protect your secrets, slay, and don't dump your credit card number into a log file. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from