File Coverage

blib/lib/Data/Radius/Dictionary.pm
Criterion Covered Total %
statement 34 37 91.8
branch 7 14 50.0
condition 1 2 50.0
subroutine 13 14 92.8
pod 1 9 11.1
total 56 76 73.6


line stmt bran cond sub pod time code
1             package Data::Radius::Dictionary;
2              
3 4     4   156689 use v5.10;
  4         36  
4 4     4   21 use strict;
  4         9  
  4         113  
5 4     4   20 use warnings;
  4         7  
  4         170  
6              
7 4     4   26 use base qw(Class::Accessor::Fast);
  4         8  
  4         2211  
8             __PACKAGE__->mk_accessors(qw(attr_id attr_name const_name const_value vnd_name vnd_id));
9              
10 4     4   13353 use Data::Radius::DictionaryParser ();
  4         16  
  4         1571  
11              
12             sub new {
13 4     4 1 95 my ($class, %h) = @_;
14 4         51 return bless({ %h }, $class);
15             }
16              
17             sub load_file {
18 4     4 0 417 my ($class, $file) = @_;
19 4         35 return Data::Radius::DictionaryParser->new()->parse_file($file);
20             }
21              
22             sub attribute {
23 19     19 0 9232 my ($self, $attr_name) = @_;
24 19 50       50 return undef if (! $attr_name);
25             # hash-ref with {id, type, vendor, parent}
26 19         503 return $self->attr_name()->{ $attr_name };
27             }
28              
29             sub attribute_name {
30 3     3 0 7 my ($self, $vendor_name, $id) = @_;
31 3   50     60 return $self->attr_id()->{ $vendor_name // '' }{$id};
32             }
33              
34             sub tlv_attribute_name {
35 3     3 0 7 my ($self, $parent, $id) = @_;
36 3         9 return $parent->{tlv_attr_id}{ $id };
37             }
38              
39             sub vendor_id {
40 5     5 0 9 my ($self, $vendor_name) = @_;
41 5 100       14 return undef if (! $vendor_name);
42 1         24 return $self->vnd_name()->{ $vendor_name };
43             }
44              
45             sub vendor_name {
46 0     0 0 0 my ($self, $vendor_id) = @_;
47 0 0       0 return undef if (! $vendor_id);
48 0         0 return $self->vnd_id()->{ $vendor_id };
49             }
50              
51             # VALUE Service-Type Login-User 1
52             # Convert 'Login-User' to 1
53             sub value {
54 1     1 0 5 my ($self, $attr_name, $const_name) = @_;
55 1 50       4 return undef if (! defined $const_name);
56 1 50       22 return $self->const_value()->{ $attr_name } ? $self->const_value()->{ $attr_name }{ $const_name } : undef;
57             }
58              
59             sub constant {
60 1     1 0 4 my ($self, $attr_name, $const_value) = @_;
61 1 50       4 return undef if (! defined $const_value);
62 1 50       29 return $self->const_name()->{ $attr_name } ? $self->const_name()->{ $attr_name }{ $const_value } : undef;
63             }
64              
65             1;
66              
67             __END__