File Coverage

blib/lib/Parse/Win32Registry.pm
Criterion Covered Total %
statement 39 45 86.6
branch 8 12 66.6
condition 1 3 33.3
subroutine 12 14 85.7
pod 1 5 20.0
total 61 79 77.2


line stmt bran cond sub pod time code
1             package Parse::Win32Registry;
2              
3 13     13   960418 use 5.008_001;
  13         155  
4 13     13   73 use strict;
  13         26  
  13         349  
5 13     13   94 use warnings;
  13         27  
  13         750  
6              
7             our $VERSION = '1.1';
8              
9 13     13   93 use base qw(Exporter);
  13         25  
  13         2221  
10              
11 13     13   98 use Carp;
  13         26  
  13         878  
12 13     13   7058 use Encode;
  13         125403  
  13         1024  
13 13     13   6544 use Parse::Win32Registry::Base qw(:all);
  13         42  
  13         3408  
14 13     13   7058 use Parse::Win32Registry::Win95::File;
  13         35  
  13         430  
15 13     13   6195 use Parse::Win32Registry::WinNT::File;
  13         44  
  13         6168  
16              
17             our @EXPORT_OK = (
18             # include old function names for backwards compatibility
19             'convert_filetime_to_epoch_time',
20             'formatted_octets',
21             @Parse::Win32Registry::Base::EXPORT_OK
22             );
23              
24             our %EXPORT_TAGS = (
25             REG_ => [grep { /^REG_[A-Z_]*$/ } @EXPORT_OK],
26             all => [@EXPORT_OK],
27             functions => [grep { /^[a-z0-9_]*$/ } @EXPORT_OK],
28             constants => [grep { /^[A-Z_]*$/ } @EXPORT_OK],
29             );
30              
31             *convert_filetime_to_epoch_time = \&Parse::Win32Registry::unpack_windows_time;
32             *formatted_octets = \&Parse::Win32Registry::format_octets;
33              
34             sub enable_warnings {
35 1     1 0 84 $Parse::Win32Registry::Base::WARNINGS = 1;
36             }
37              
38             sub disable_warnings {
39 1     1 0 81 $Parse::Win32Registry::Base::WARNINGS = 0;
40             }
41              
42             sub set_codepage {
43 0     0 0 0 my $codepage = shift;
44 0 0       0 if (defined $codepage) {
45 0         0 $Parse::Win32Registry::Base::CODEPAGE = $codepage;
46             }
47             }
48              
49             sub get_codepage {
50 0     0 0 0 $Parse::Win32Registry::Base::CODEPAGE;
51             }
52              
53             sub new {
54 54     54 1 43056 my $class = shift;
55 54 100       480 my $filename = shift or croak "No filename specified";
56              
57 53 50       2031 open my $regfile, "<", $filename or croak "Unable to open '$filename': $!";
58 53         545 sysread($regfile, my $sig, 4);
59 53 50 33     375 if (!defined($sig) || length($sig) != 4) {
60 0         0 warnf("Could not read registry file header");
61 0         0 return;
62             }
63 53         480 close $regfile;
64              
65 53 100       271 if ($sig eq "CREG") {
    100          
66             # attempt to parse this as a Windows 95 Registry File
67 16         133 return Parse::Win32Registry::Win95::File->new($filename);
68             }
69             elsif ($sig eq "regf") {
70             # attempt to parse this as a Windows NT Registry File
71 35         301 return Parse::Win32Registry::WinNT::File->new($filename);
72             }
73             else {
74 2         10 warnf("Invalid registry file header");
75 2         35 return;
76             }
77             }
78              
79             1;
80              
81             __END__