File Coverage

blib/lib/Parse/Win32Registry/Value.pm
Criterion Covered Total %
statement 45 47 95.7
branch 14 14 100.0
condition 5 6 83.3
subroutine 11 12 91.6
pod 0 7 0.0
total 75 86 87.2


line stmt bran cond sub pod time code
1             package Parse::Win32Registry::Value;
2              
3 13     13   82 use strict;
  13         25  
  13         408  
4 13     13   63 use warnings;
  13         25  
  13         338  
5              
6 13     13   62 use base qw(Parse::Win32Registry::Entry);
  13         24  
  13         971  
7              
8 13     13   70 use Carp;
  13         38  
  13         891  
9 13     13   71 use Parse::Win32Registry::Base qw(:all);
  13         21  
  13         11191  
10              
11             sub get_name {
12 482     482 0 70922 my $self = shift;
13              
14 482         1933 return $self->{_name};
15             }
16              
17             sub get_type {
18 1126     1126 0 1565 my $self = shift;
19              
20 1126         3539 return $self->{_type};
21             }
22              
23             our @Types = qw(
24             REG_NONE
25             REG_SZ
26             REG_EXPAND_SZ
27             REG_BINARY
28             REG_DWORD
29             REG_DWORD_BIG_ENDIAN
30             REG_LINK
31             REG_MULTI_SZ
32             REG_RESOURCE_LIST
33             REG_FULL_RESOURCE_DESCRIPTOR
34             REG_RESOURCE_REQUIREMENTS_LIST
35             REG_QWORD
36             );
37              
38             sub get_type_as_string {
39 202     202 0 368 my $self = shift;
40              
41 202         506 my $type = $self->get_type;
42 202 100       644 if (exists $Types[$type]) {
43 196         791 return $Types[$type];
44             }
45             else {
46             # Return unrecognised types as REG_
47             # REGEDIT displays them as formatted hex numbers, e.g. 0x1f4
48 6         27 return "REG_$type";
49             }
50             }
51              
52             sub get_data_as_string {
53 202     202 0 349 my $self = shift;
54              
55 202         530 my $type = $self->get_type;
56 202         730 my $data = $self->get_data;
57 202 100 66     2052 if (!defined($data)) {
    100 100        
    100          
    100          
    100          
58 36         144 return '(invalid data)';
59             }
60             elsif (length($data) == 0) {
61 30         235 return '(no data)';
62             }
63             elsif ($type == REG_SZ || $type == REG_EXPAND_SZ) {
64 14         55 return $data;
65             }
66             elsif ($type == REG_MULTI_SZ) {
67 38         128 my @data = $self->get_data;
68 38         71 my $i = 0;
69 38         76 return join(' ', map { "[" . $i++ . "] $_" } @data);
  90         419  
70             }
71             elsif ($type == REG_DWORD || $type == REG_DWORD_BIG_ENDIAN) {
72 70         490 return sprintf '0x%08x (%u)', $data, $data;
73             }
74             else {
75 14         128 return join(' ', unpack('(H2)*', $data));
76             }
77             }
78              
79             sub get_raw_data {
80 92     92 0 69106 my $self = shift;
81              
82 92         710 return $self->{_data};
83             }
84              
85             sub as_string {
86 110     110 0 270 my $self = shift;
87              
88 110         392 my $name = $self->get_name;
89 110 100       598 $name = '(Default)' if $name eq '';
90 110         463 my $type_as_string = $self->get_type_as_string;
91 110         267 my $data_as_string = $self->get_data_as_string;
92 110         923 return "$name ($type_as_string) = $data_as_string";
93             }
94              
95             sub print_summary {
96 0     0 0   my $self = shift;
97              
98 0           print $self->as_string, "\n";
99             }
100              
101             1;