blib/lib/STUN/Attributes.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 35 CC 1 SCAR 6.9
CC
1
Cov
0%
attr_message
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1  
2 package STUN::Attributes;
3  
4 use strict;
5  
6 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
7  
8 require Exporter;
9  
10 @ISA = qw(Exporter);
11 @EXPORT = qw(attr_message);
12 $VERSION='0.01';
13  
14 my %attr_code = (
15 '0001' => 'MappedAddress',
16 '0002' => 'ResponseAddress',
17 '0003' => 'ChangeRequest',
18 '0004' => 'SourceAddress',
19 '0005' => 'ChangedAddress',
20 '0006' => 'Username',
21 '0007' => 'Password',
22 '0008' => 'MessageIntegrity',
23 '0009' => 'ErrorCode',
24 '000A' => 'UnknownAttribute',
25 '000B' => 'ReflectedFrom',
26 '0021' => 'XorOnly',
27 '8020' => 'XorMappedAddress',
28 '8022' => 'ServerName',
29 '8050' => 'SecondaryAddress', # Non-standard extention.
30 );
31  
32 my $mnemonicCode = '';
33 my ($code, $message);
34 while (($code, $message) = each %attr_code) {
35 # create mnemonic subroutines
36 $message =~ tr/a-z \-/A-Z__/;
37 $mnemonicCode .= "sub STUN_$message () { \"$code\" }\n";
38 $mnemonicCode .= "*RC_$message = \\&STUN_$message;\n"; # legacy
39 $mnemonicCode .= "push(\@EXPORT_OK, 'STUN_$message');\n";
40 $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n";
41 }
42 eval $mnemonicCode; # only one eval for speed
43 die if $@;
44  
45  
46 %EXPORT_TAGS = (
47 constants => [grep /^STUN_/, @EXPORT_OK],
48 );
49  
50 sub attr_message ($) { $attr_code{$_[0]} };
51  
52 1;
53  
54 __END__