File: Immutable.pm

package info (click to toggle)
liblist-objects-withutils-perl 2.028003-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,276 kB
  • sloc: perl: 1,957; makefile: 17; sh: 6
file content (61 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package List::Objects::WithUtils::Hash::Immutable;
$List::Objects::WithUtils::Hash::Immutable::VERSION = '2.028003';
use strictures 2;

require Role::Tiny;
Role::Tiny->apply_roles_to_package( __PACKAGE__,
  qw/
    List::Objects::WithUtils::Role::Hash
    List::Objects::WithUtils::Role::Hash::Immutable
  /,
);

use Exporter ();
our @EXPORT = 'immhash';

sub import {
  my $pkg = caller;
  { no strict 'refs';
    ${"${pkg}::a"} = ${"${pkg}::a"}; ${"${pkg}::b"} = ${"${pkg}::b"};
  }
  goto &Exporter::import
}

sub immhash { __PACKAGE__->new(@_) }

1;

=pod

=head1 NAME

List::Objects::WithUtils::Hash::Immutable - Immutable hash objects

=head1 SYNOPSIS

  use List::Objects::WithUtils 'immhash';
  my $hash = immhash( foo => 1, bar => 2 );

=head1 DESCRIPTION

These are immutable hash objects; attempting to call list-mutating methods
(or modify the backing hash directly) will throw an exception.

This class consumes the following roles, which contain most of the relevant
documentation:

L<List::Objects::WithUtils::Role::Hash>

L<List::Objects::WithUtils::Role::Hash::Immutable>

(See L<List::Objects::WithUtils::Hash> for a mutable implementation.)

=head2 immhash

Creates a new immutable hash object.

=head1 AUTHOR

Jon Portnoy <avenj@cobaltirc.org>

=cut