develooper Front page | perl.perl5.porters | Postings from May 2000

Re: Proposed pragma: readonly

From:
Tom Christiansen
Date:
May 20, 2000 06:56
Subject:
Re: Proposed pragma: readonly
Message ID:
31639.958830951@chthon
I've always used this:

    XS(XS_Const_const)
    {
	register int i;

	dXSARGS;
	for (i = 0; i < items; i++) { SvREADONLY_on(ST(i)); }
	XSRETURN(1);
    }

    XS(boot_Const)
    {
	dXSARGS;
	char* file = __FILE__;

	newXS("Const::const", XS_Const_const, file);
	ST(0) = &sv_yes;
	XSRETURN(1);
    }

Its manpage is:

    NAME
	   Const - Perl module that sets variables to readonly

    SYNOPSIS
	       use Const;
	       ...
	       const $a = 3, $b = 2;
	       ...
	       $b = 1;  # Error: $b is read only

    DESCRIPTION
	   This package implements only one function, const.

	   Any variable given as an argument to const will be marked
	   so that subsequent assignment will result in an error.
	   The result of providing a non-scalar argument is
	   undefined.  const returns its first argument.

    AUTHOR
	   William Setzer <William_Setzer@ncsu.edu>



--tom



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About