Attribute-Lexical

 view release on metacpan or  search on metacpan

lib/Attribute/Lexical.pm  view on Meta::CPAN

=item Attribute::Lexical->unimport(NAME [=> HANDLER], ...)

Sets up negative lexical attribute declarations, in the lexical
environment that is currently compiling.  Each I<NAME> must be
an attribute name (e.g., "B<CODE:Funky>").  If the name is given
on its own, it is lexically dissociated from any handler function.
Within the resulting scope, the attribute name will not be recognised.
If a I<HANDLER> (which must be a function reference) is specified with
a name, the name will be dissociated if and only if it is currently
handled by that function.

=cut

sub unimport {
	my $class = shift(@_);
	croak "$class does no default unimportation" if @_ == 0;
	$^H |= 0x20000 if _KLUDGE_HINT_LOCALIZE_HH;   # implicit in later perls
	for(my $i = 0; $i != @_; ) {
		my $name = $_[$i++];
		_check_attribute_name($name);
		my $handler = is_ref($_[$i], "CODE") ? $_[$i++] : undef;
		my $key = "Attribute::Lexical/$name";
		next unless exists $^H{$key};
		if($handler) {
			next unless $interned_handler{$^H{$key}} == $handler;
		}
		delete $^H{$key};
	}
}

=back

=head1 BUGS

This module uses relatively new and experimental features of Perl, and
is liable to expose problems in the interpreter.  On older versions of
Perl some of the necessary infrastructure is missing, so the module uses
workarounds, with varying degrees of success.  Specifically:

Prior to Perl 5.9.4, the lexical state of attribute declarations is not
available at runtime.  Most attributes are handled at compile time,
when the lexical state is available, so the module largely works.
But C<my>/C<state> variables have attributes applied at runtime,
which won't work.  Usually the attributes will be simply unavailable
at runtime, as if they were never declared, but some rare situations
involving declaring attributes inside a C<BEGIN> block can confuse the
module into applying the wrong attribute handler.

Prior to Perl 5.9.3, the lexical state of attribute declarations does
not propagate into string eval.

Prior to Perl 5.8, attributes don't work at all on C<our> variables.
Only function attributes can be used effectively on such old versions.

This module tries quite hard to play nicely with other modules that manage
attributes, in particular L<Attribute::Handlers>.  However, the underlying
protocol for attribute management is tricky, and convoluted arrangements
of attribute managers are liable to tread on each other's toes.

The management of handler functions is likely to run into trouble where
threads are used.  Code compiled before any threads are created should
be OK, as should anything contained entirely within a single thread,
but code shared between threads will probably have trouble due to Perl
not properly sharing data structures.

=head1 SEE ALSO

L<Attribute::Handlers>,
L<attributes>

=head1 AUTHOR

Andrew Main (Zefram) <zefram@fysh.org>

=head1 COPYRIGHT

Copyright (C) 2009, 2010, 2011, 2017
Andrew Main (Zefram) <zefram@fysh.org>

=head1 LICENSE

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1;



( run in 1.800 second using v1.01-cache-2.11-cpan-39bf76dae61 )