Acme-Playpen

 view release on metacpan or  search on metacpan

lib/Acme/Playpen/_common.pm  view on Meta::CPAN

package Acme::Playpen::_common;

use 5.006;
use strict;
use warnings;

sub new {
    my $class = shift;
    return bless {}, $class;
}

1;

lib/Tupelo/Munge.pm  view on Meta::CPAN

be referenced in other places, for example by being a package variable.
A tuple slot is not itself a referencable object.  Operations on
an arbitrary slot of a tuple, identified by index, are efficient.
Operating on all the slots simultaneously is also efficient.

In general it is possible to mutate an existing tuple.  It is possible
to write to any slot within a tuple (either emptying it or writing in an
object reference), and it is also possible to replace a tuple's entire
sequence of slot values with a different one.  A tuple can be marked as
read-only to prevent any mutation.  A tuple thus being immutable only
prevents mutation of the tuple's sequence of slot values (and blessing
of the tuple); it doesn't affect mutation of the objects referenced by
the tuple.

It is possible for mutation to change the number of slots in a tuple,
but this is a relatively expensive operation that should be avoided.
Other than writing to a single slot and replacement of the complete
sequence of slot values, tuples do not naturally support operations to
edit the slot value sequence, such as adding an object reference onto
the end of a tuple.  Such an operation can be constructed via complete
replacement of a tuple's slot value sequence, but if the desire to do
that arises then it suggests that an array would be a more appropriate
data structure.

A tuple can be identified as such through the
L<C<builtin::reftype>|builtin/reftype> function, which will return
C<OBJECT> when given a reference to one.  Correspondingly, the
L<C<ref>|perlfunc/ref> function will return C<OBJECT> if given a reference
to an unblessed tuple, and the default stringification of a reference to a
tuple will include C<OBJECT>.  Beware that this usage of the word "object"
is confusing: it was already a somewhat overloaded term before the tuple
data type existed, so it makes a poor way to identify the tuple data type.

Via this module, a tuple can be constructed from a list of slot values,
and the slot values in a tuple can be read and written.  This module
represents each slot value in the form of a reference value (for a slot
referencing an object) or an undefined value (for an empty slot).

=head2 Core class system

The L<Perl core class system|perlclass> (introduced alongside tuples in
Perl 5.37.9) uses tuples as the representation format for its classful
objects.  This class system is not the subject of this module, but it
has a special relationship to the tuple data type, which is worthy of
comment.  Beware that the core documentation overloads the term "class",
using it both to refer to Perl classes in general (i.e., packages into
which objects get blessed) and to refer specifically to the classes of
this class system.

A blessed object constructed through the automatically-generated
constructor for a core class system class is always a tuple object,
and its slots reference the field variables for that class and its
superclasses.  The field variables can only be scalars, arrays, and
hashes, so those are the only types of objects that will be referenced
by such tuples.  Once the object is fully constructed and visible as
C<$self> to method code, none of the tuple slots are empty, and the
sequence of object references never subsequently changes.

Beware that mutating a tuple used as the representation of one of these
blessed objects can easily cause malfunction of its class.  Of course,
the same goes for mutating the innards of any data structure representing
a classful object.

=head2 Experimental status

The tuple data type as supplied by the Perl core is experimental.
This means that it could change significantly, or be removed entirely,
in a future version of Perl.

Furthermore, the manner in which this module uses the tuple data type

lib/Tupelo/Munge.pm  view on Meta::CPAN


=item tuple_seal(TUPLE)

I<TUPLE> must be a reference to a mutable tuple.  Makes the tuple
immutable.  Returns a reference to the tuple (i.e., a copy of I<TUPLE>).

=back

=head1 BUGS

As of Perl 5.37.10, the L<C<bless>|perlfunc/bless> function in the Perl
core has a problem with tuples.  Although it will bless an unblessed
tuple just as it will any other object, it refuses to bless a tuple that
is already blessed.  It permits reblessing of objects other than tuples,
and so is discriminating against tuples.  This prohibition appears to
be a result of concern for the integrity of classes of the core class
system, but isn't actually justified by such concerns.  (It was added
alongside the prohibition on manually blessing into classes of the core
class system, a prohibition which is justified by such concerns.)

As of Perl 5.37.10, the Perl core provides no coherent semantics regarding
the mutability of tuples.  It does not enforce immutability, by looking at
any flag attached to a tuple.  This means that the immutability offered
by this module can be violated by exploiting core features.  But the
core also assumes in some situations that tuples will not be mutated.
This immutability assumed by the core can be violated by the use of this
module, or by exploiting core features without any use of this module.



( run in 1.460 second using v1.01-cache-2.11-cpan-de7293f3b23 )