develooper Front page | perl.perl5.porters | Postings from February 2008

[PATCH] Read-only variable tests

Thread Next
From:
Jerry D. Hedden
Date:
February 8, 2008 11:07
Subject:
[PATCH] Read-only variable tests
Message ID:
1ff86f510802081106l737e4dcdibb73c8eacb4c39d8@mail.gmail.com
I discovered that there was no comprehensive testing of
read-only variables.  Attached is a patch to add lots more
tests to lib/Internals.t.

There are some issues associated with all this:

Read-only scalar:
    undef               Fails = okay
    modify              Fails = okay

Read-only array:
    undef               Fails = okay
    reassign            Fails = okay
    shift               Fails = okay
    push                Fails = okay
    delete elem         Fails = okay
    modify elem         Works = marked as TODO

Read-only array element:
    modify              Fails = okay
    undef               Fails = okay
    delete              Works = marked as TODO

    The read-only status on an array element is not fixed to
    the array position, but to the element.  When the array
    is shifted or unshifed, the read-only element moves:

        Internals::SvREADONLY($foo[2], 1);
        shift(@foo);    # $foo[1] is now read-only

    Is this the correct behavior, or should the read-only
    status be associated with the array position?

Read-only hash:
    undef               Fails = okay
    reassign            Raises exception, but hash is cleared
                            = marked as TODO
    add key             Fails = okay
    modify key's value  Works because it's designed that way
                          for Hash::Util = okay
    delete key          Works because it's designed that way
                          for Hash::Util = okay
    add back deleted keys
                        Works because it's designed that way
                          for Hash::Util = okay

Read-only hash value:
    modify              Fails = okay
    undef               Fails = okay
    delete              Works because it's designed that way
                          for Hash::Util = okay

The three TODOs are the result of the implementation of
restricted hashes for Hash::Util, and since
Internals::SvREADONLY is not explicitly documented, I
suppose they don't require any 'fixes'.

Thread Next


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