Const::Fast(3pm)

✨ NAME ✨

okay bestie, you're reading the Const::Fast(3pm) manual page β€” yes, that's the manual name folded in right at the top, from the User Contributed Perl Documentation, and no we are not copy-pasting the header line, we're being cute about it πŸ’…. This module is literally a facility for creating read-only scalars, arrays, and hashes. It's giving immutability main character energy, fr fr.

🌸 VERSION 🌸

version 0.014 β€” iconic number, no cap.

πŸ¦‹ SYNOPSIS πŸ¦‹

use Const::Fast;

const my $foo => 'a scalar value';
const my @bar => qw/a list value/;
const my %buz => (a => 'hash', of => 'something');

πŸ‘‘ SUBROUTINES/METHODS πŸ‘‘

πŸ’… const $var, $value

πŸ’… const @var, @value...

πŸ’… const %var, %value...

This is the only function of this module, and it is exported by default. It takes a scalar, array or hash lvalue as first argument, and a list of one or more values depending on the type of the first argument as the value for the variable. It will set the variable to that value and subsequently make it readonly. Arrays and hashes will be made deeply readonly. Obsessed.

Exporting is done using Sub::Exporter::Progressive. You may need to depend on Sub::Exporter explicitly if you need the latter's flexibility. iykyk.

πŸ”₯ RATIONALE πŸ”₯

This module was written because the author stumbled on some serious issues of Readonly that aren't easily fixable without breaking backwards compatibility in subtle ways. In particular Readonly's use of ties is a source of subtle bugs and bad performance. Not the vibe. Instead, this module uses the builtin readonly feature of perl, making access to the variables just as fast as any normal variable without the weird side-effects of ties. Slay.

Readonly can do the same for scalars when Readonly::XS is installed, but chooses not to do so in the most common case. This may change in the future if someone takes up maintenance of Readonly, and the two modules may be convergence if that happens. Periodt.

⚠️ CAVEATS ⚠️

🚨 bestie, important caveat energy: Perl doesn't distinguish between restricted hashes and readonly hashes. This means that:
use Const::Fast;
const my %a => (foo => 1, bar => 2);
say 1 unless $a{baz}
Will give the error "Attempt to access disallowed key 'baz' in a restricted hash". You have to use exists $a{baz} instead. This is a limitation of perl that can hopefully be solved in the future. Not me crying about restricted hashes 😭.

🫢 ACKNOWLEDGEMENTS 🫢

The interface for this module was inspired by Eric Roode's Readonly. The implementation is inspired by doing everything the opposite way Readonly does it. Chaotic? Maybe. Iconic? Absolutely. πŸ’œ

πŸ’Œ AUTHOR πŸ’Œ

Leon Timmermans <fawaka@gmail.com> β€” author icon, we stan.

This software is copyright (c) 2010 by Leon Timmermans.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


πŸ’– okay that's the whole page, bestie! source/version: perl v5.42.0; date: 2014-11-23; manual: Const::Fast(3pm). go make your variables readonly and slay πŸ’…βœ¨

πŸ“¦ where this page comes from