App-SimpleBackuper
view release on metacpan or search on metacpan
local/lib/perl5/Const/Fast.pm view on Meta::CPAN
elsif (reftype $_[0] eq 'ARRAY') {
@{ $_[0] } = @args;
}
elsif (reftype $_[0] eq 'HASH') {
croak 'Odd number of elements in hash assignment' if @args % 2;
%{ $_[0] } = @args;
}
else {
croak 'Can\'t make variable readonly';
}
_make_readonly($_[0], 1);
return;
}
1; # End of Const::Fast
# ABSTRACT: Facility for creating read-only scalars, arrays, and hashes
__END__
=pod
=head1 NAME
Const::Fast - Facility for creating read-only scalars, arrays, and hashes
=head1 VERSION
version 0.014
=head1 SYNOPSIS
use Const::Fast;
const my $foo => 'a scalar value';
const my @bar => qw/a list value/;
const my %buz => (a => 'hash', of => 'something');
=head1 SUBROUTINES/METHODS
=head2 const $var, $value
=head2 const @var, @value...
=head2 const %var, %value...
This the only function of this module and it is exported by default. It takes a scalar, array or hash lvalue as first argument, and a list of one or more values depending on the type of the first argument as the value for the variable. It will set th...
Exporting is done using Sub::Exporter::Progressive. You may need to depend on Sub::Exporter explicitly if you need the latter's flexibility.
=head1 RATIONALE
This module was written because I stumbled on some serious issues of L<Readonly> that aren't easily fixable without breaking backwards compatibility in subtle ways. In particular Readonly's use of ties is a source of subtle bugs and bad performance. ...
=head1 CAVEATS
Perl doesn't distinguish between restricted hashes and readonly hashes. This means that:
use Const::Fast;
const my %a => (foo => 1, bar => 2);
say 1 unless $a{baz}
Will give the error "Attempt to access disallowed key 'baz' in a restricted hash". You have to use C<exists $a{baz}> instead. This is a limitation of perl that can hopefully be solved in the future.
=head1 ACKNOWLEDGEMENTS
The interface for this module was inspired by Eric Roode's L<Readonly>. The implementation is inspired by doing everything the opposite way Readonly does it.
=head1 AUTHOR
Leon Timmermans <fawaka@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 1.530 second using v1.01-cache-2.11-cpan-9e1a9122474 )