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   106 use strict;
  13         28  
  13         377  
4 13     13   69 use warnings;
  13         27  
  13         383  
5              
6 13     13   69 use base qw(Parse::Win32Registry::Entry);
  13         32  
  13         1480  
7              
8 13     13   93 use Carp;
  13         27  
  13         892  
9 13     13   90 use Parse::Win32Registry::Base qw(:all);
  13         26  
  13         8863  
10              
11             sub get_name {
12 482     482 0 36734 my $self = shift;
13              
14 482         1524 return $self->{_name};
15             }
16              
17             sub get_type {
18 1126     1126 0 1827 my $self = shift;
19              
20 1126         2476 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         469 my $type = $self->get_type;
42 202 100       544 if (exists $Types[$type]) {
43 196         678 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         30 return "REG_$type";
49             }
50             }
51              
52             sub get_data_as_string {
53 202     202 0 342 my $self = shift;
54              
55 202         439 my $type = $self->get_type;
56 202         616 my $data = $self->get_data;
57 202 100 66     1289 if (!defined($data)) {
    100 100        
    100          
    100          
    100          
58 36         130 return '(invalid data)';
59             }
60             elsif (length($data) == 0) {
61 30         103 return '(no data)';
62             }
63             elsif ($type == REG_SZ || $type == REG_EXPAND_SZ) {
64 14         51 return $data;
65             }
66             elsif ($type == REG_MULTI_SZ) {
67 38         117 my @data = $self->get_data;
68 38         82 my $i = 0;
69 38         84 return join(' ', map { "[" . $i++ . "] $_" } @data);
  90         414  
70             }
71             elsif ($type == REG_DWORD || $type == REG_DWORD_BIG_ENDIAN) {
72 70         492 return sprintf '0x%08x (%u)', $data, $data;
73             }
74             else {
75 14         117 return join(' ', unpack('(H2)*', $data));
76             }
77             }
78              
79             sub get_raw_data {
80 92     92 0 48545 my $self = shift;
81              
82 92         457 return $self->{_data};
83             }
84              
85             sub as_string {
86 110     110 0 218 my $self = shift;
87              
88 110         291 my $name = $self->get_name;
89 110 100       309 $name = '(Default)' if $name eq '';
90 110         273 my $type_as_string = $self->get_type_as_string;
91 110         276 my $data_as_string = $self->get_data_as_string;
92 110         756 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;