On Sat, Dec 27, 2008 at 12:15, Mr. Shawn H. Corey <shawnhco...@magma.ca> wrote:
> On Sat, 2008-12-27 at 11:51 -0500, Chas. Owens wrote:
>> * only if you have Readonly::XS installed, otherwise it uses a tied
>> variable that throws an error when STORE is called.
>
> The problem with Readonly et al. is that it is not a standard module.  I
> have worked in places that do not allow anything but standard modules on
> their servers; they too afraid that other modules may contain malware.
> Because of this, I am reluctant to recommend it; it is not always
> available.
>
> Aside from that, it is a true constant :  you can use it anywhere you
> can use a variable.
snip

I too have worked at places that have these sorts of obnoxious
policies.  Most often I have found that the policy has been created by
lazy sysadmins who don't want to take the time to install the modules
(or learn how, since often they don't even know how).  If this is the
case you can often get by with installing the modules into the home
directory of the user who is to run the code (and using the lib pragma
or PERL5_LIB).  There have been a few places where it was a real
security issue (as opposed to just lazy sysadmins).  At those places,
my first answer was to request a code review for the module in
question.  If they balk claiming it will take too long, point out that
if you were to write the module's functionality from scratch it would
take a long time and they would still need to review as much code.
Sometimes this doesn't work, and then my general answer is to look at
how the module implemented the functionality I desired and then
reinvented the wheel. In this case, it would be trivial (as all you
are doing is setting a flag on the scalar variable).  In fact, the
code for Readonly::XS boils down to two short XS functions that expose
two functions from the guts of perl:

int
is_sv_readonly(sv)
    SV *sv
PROTOTYPE: $
CODE:
    RETVAL = SvREADONLY(sv);
OUTPUT:
    RETVAL

void
make_sv_readonly(sv)
    SV *sv
PROTOTYPE: $
CODE:
    SvREADONLY_on(sv);

And you don't even need the first function.  The code for Readonly is
trivial once you realize that it is just using tied variables where
STORE (and any other functions that can modify the value of the
variable) throws an error.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to