File Coverage

blib/lib/Crypt/OpenPGP/Constants.pm
Criterion Covered Total %
statement 21 21 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 29 30 96.6


line stmt bran cond sub pod time code
1             package Crypt::OpenPGP::Constants;
2 14     14   724 use strict;
  14         68  
  14         602  
3 14     14   82 use warnings;
  14         55  
  14         4668  
4              
5             our $VERSION = '1.19'; # VERSION
6              
7             our %CONSTANTS = (
8             'PGP_PKT_PUBKEY_ENC' => 1,
9             'PGP_PKT_SIGNATURE' => 2,
10             'PGP_PKT_SYMKEY_ENC' => 3,
11             'PGP_PKT_ONEPASS_SIG' => 4,
12             'PGP_PKT_SECRET_KEY' => 5,
13             'PGP_PKT_PUBLIC_KEY' => 6,
14             'PGP_PKT_SECRET_SUBKEY' => 7,
15             'PGP_PKT_COMPRESSED' => 8,
16             'PGP_PKT_ENCRYPTED' => 9,
17             'PGP_PKT_MARKER' => 10,
18             'PGP_PKT_PLAINTEXT' => 11,
19             'PGP_PKT_RING_TRUST' => 12,
20             'PGP_PKT_USER_ID' => 13,
21             'PGP_PKT_PUBLIC_SUBKEY' => 14,
22             'PGP_PKT_USER_ATTRIBUTE' => 17,
23             'PGP_PKT_ENCRYPTED_MDC' => 18,
24             'PGP_PKT_MDC' => 19,
25              
26             'DEFAULT_CIPHER' => 2,
27             'DEFAULT_DIGEST' => 2,
28             'DEFAULT_COMPRESS' => 1,
29             );
30              
31             our %TAGS;
32             my %RULES = (
33             '^PGP_PKT' => 'packet',
34             );
35              
36             for my $re (keys %RULES) {
37             $TAGS{ $RULES{$re} } = [ grep /$re/, keys %CONSTANTS ];
38             }
39              
40             sub import {
41 96     96   285 my $class = shift;
42              
43 96         194 my @to_export;
44 96         313 my @args = @_;
45 96         306 for my $item (@args) {
46             push @to_export,
47 187 100       715 $item =~ s/^:// ? @{ $TAGS{$item} } : $item;
  13         181  
48             }
49              
50 14     14   119 no strict 'refs';
  14         36  
  14         3222  
51 96         315 my $pkg = caller;
52 96         508 for my $con (@to_export) {
53             warn __PACKAGE__, " does not export the constant '$con'"
54 395 50       1131 unless exists $CONSTANTS{$con};
55 395     627   16537 *{"${pkg}::$con"} = sub () { $CONSTANTS{$con} }
  627         7653  
56 395         1696 }
57             }
58              
59             1;
60             __END__