File Coverage

blib/lib/Specio/Registry.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 6 83.3
condition 4 7 57.1
subroutine 7 7 100.0
pod 0 3 0.0
total 41 48 85.4


line stmt bran cond sub pod time code
1             package Specio::Registry;
2              
3 32     32   199 use strict;
  32         59  
  32         1174  
4 32     32   150 use warnings;
  32         62  
  32         1686  
5              
6 32     32   161 use parent 'Exporter';
  32         70  
  32         2199  
7              
8             our $VERSION = '0.53';
9              
10 32     32   2874 use Carp qw( confess croak );
  32         64  
  32         11933  
11              
12             our @EXPORT_OK
13             = qw( exportable_types_for_package internal_types_for_package register );
14              
15             my %Registry;
16              
17             sub register {
18 3332 50 33 3332 0 15129 confess
19             'register requires three or four arguments (package, name, type, [exportable])'
20             unless @_ == 3 || @_ == 4;
21              
22 3332         5291 my $package = shift;
23 3332         4871 my $name = shift;
24 3332         4534 my $type = shift;
25 3332         4925 my $exportable = shift;
26              
27             croak "The $package package already has a type named $name"
28 3332 100       9115 if $Registry{$package}{internal}{$name};
29              
30             # This is structured so that we can always return a _reference_ for
31             # *_types_for_package. This means that the generated t sub sees any
32             # changes to the registry as they happen. This is important inside a
33             # package that is declaring new types. It needs to be able to see types it
34             # has declared.
35 3331         7519 $Registry{$package}{internal}{$name} = $type;
36 3331 100       7253 $Registry{$package}{exportable}{$name} = $type
37             if $exportable;
38              
39 3331         9103 return;
40             }
41              
42             sub exportable_types_for_package {
43 183     183 0 354 my $package = shift;
44              
45 183   50     890 return $Registry{$package}{exportable} ||= {};
46             }
47              
48             sub internal_types_for_package {
49 294     294 0 587 my $package = shift;
50              
51 294   100     2648 return $Registry{$package}{internal} ||= {};
52             }
53              
54             1;
55              
56             # ABSTRACT: Implements the per-package type registry
57              
58             __END__
59              
60             =pod
61              
62             =encoding UTF-8
63              
64             =head1 NAME
65              
66             Specio::Registry - Implements the per-package type registry
67              
68             =head1 VERSION
69              
70             version 0.53
71              
72             =head1 DESCRIPTION
73              
74             There's nothing public here.
75              
76             =for Pod::Coverage .*
77              
78             =head1 SUPPORT
79              
80             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
81              
82             =head1 SOURCE
83              
84             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
85              
86             =head1 AUTHOR
87              
88             Dave Rolsky <autarch@urth.org>
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This software is Copyright (c) 2012 - 2025 by Dave Rolsky.
93              
94             This is free software, licensed under:
95              
96             The Artistic License 2.0 (GPL Compatible)
97              
98             The full text of the license can be found in the
99             F<LICENSE> file included with this distribution.
100              
101             =cut