in reply to Re^4: why doesn't constant work?
in thread why doesn't constant work?
To include XS module in dynamically linked Perl interpreters, you at least need permission to compile and install C libraries - not always a straight forward matter in corporate environments or when you are developing for a client environment rather than one you have personal control over.The phrase "if X is installed, Y will be 20 times faster" is often a good start.
But a variable being readonly isn't a requirement for correctness. It's a development tool. So you can do something like:
You'll have your Readonly variables in development, and no dependency in production.BEGIN { if (IS_PRODUCTION) { eval <<'SUB'; sub Readonly (\[$@%]@) { given (ref $_[0]) { when ('SCALAR') {${$_[0]} = $_[1]} when ('ARRAY') {@{$_[0]} = @_[1 .. $#_]} when ('HASH') {%{$_[0]} = @_[1 .. $#_]} } } SUB } else { require Readonly; Readonly->import; } }
|
|---|