File: Windows.pm

package info (click to toggle)
libsystem-info-perl 0.066-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,904 kB
  • sloc: perl: 2,516; sh: 25; makefile: 2
file content (134 lines) | stat: -rw-r--r-- 3,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package System::Info::Windows;

use strict;
use warnings;

use base "System::Info::Base";

our $VERSION = "0.051";

=head1 NAME

System::Info::Windows - Object for specific Windows info.

=head1 DESCRIPTION

=head2 $si->prepare_sysinfo

Use os-specific tools to find out more about the system.

=cut

sub prepare_sysinfo {
    my $self = shift;
    $self->SUPER::prepare_sysinfo;
    $self->prepare_os;

    my $reginfo = __get_registry_sysinfo ();
    my $envinfo = __get_environment_sysinfo ();

    for my $key (qw/__cpu_type __cpu __cpu_count/) {
	my $value = $reginfo->{$key} || $envinfo->{$key};
	$value and $self->{$key} = $value;
	}
    return $self;
    } # prepare_sysinfo

=head2 $si->prepare_os

Use os-specific tools to find out more about the operating system.

=cut

sub prepare_os {
    my $self = shift;

    eval { require Win32 };
    $@ and return;

    my $os = $self->_os;
    # ("Win7", "Windows 7 Professional (64-bit) Service Pack 1")
    $os = "$^O - " . join " " => Win32::GetOSName ();
    $os =~ s/Service\s+Pack\s+/SP/;
    $self->{__os} = $os;

    # Windows 7 Professional (64-bit) Service Pack 1
    $self->{__osname} = Win32::GetOSDisplayName ();

    # https://metacpan.org/pod/Win32#Win32::GetOSVersion()
    # ("Service Pack 1", 6, 1, 7601, 2,   1, 0, 0x100, 1)
    my ($name, $major, $minor, $build, $id,
	$spmaj, $spmin, $suitemask, $producttype) = Win32::GetOSVersion ();
    $self->{__osvers} = join "." => $major, $minor, $build;
    } # prepare_os

sub __get_registry_sysinfo {
    eval { require Win32::TieRegistry };
    $@ and return;

    Win32::TieRegistry->import;
    my $Registry = $Win32::TieRegistry::Registry->Open (
	"", { Access => 0x2000000 });

    my $basekey = join "\\" =>
	qw(LMachine HARDWARE DESCRIPTION System CentralProcessor);

    my $pnskey = "$basekey\\0\\ProcessorNameString";
    my $cpustr = $Registry->{$pnskey};

    my $idkey = "$basekey\\0\\Identifier";
    $cpustr ||= $Registry->{ $idkey };
    $cpustr =~ tr/ / /s;

    my $mhzkey = "$basekey\\0\\~MHz";
    $cpustr .= sprintf "(~%d MHz)", hex $Registry->{$mhzkey};
    my $cpu = $cpustr;

    my $ncpu = keys %{$Registry->{$basekey}};

    my ($cpu_type) = $Registry->{$idkey} =~ /^(\S+)/;

    return {
	__cpu_type  => $cpu_type,
	__cpu       => $cpu,
	__cpu_count => $ncpu,
	};
    } # __get_registry_sysinfo

sub __get_environment_sysinfo {
    return {
	__cpu_type  => $ENV{PROCESSOR_ARCHITECTURE},
	__cpu       => $ENV{PROCESSOR_IDENTIFIER},
	__cpu_count => $ENV{NUMBER_OF_PROCESSORS},
	};
    } # __get_environment_sysinfo

1;

__END__

=head1 COPYRIGHT AND LICENSE

(c) 2016-2025, Abe Timmerman & H.Merijn Brand, All rights reserved.

With contributions from Jarkko Hietaniemi, Campo Weijerman, Alan Burlison,
Allen Smith, Alain Barbet, Dominic Dunlop, Rich Rauenzahn, David Cantrell.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

See:

=over 4

=item * L<http://www.perl.com/perl/misc/Artistic.html>

=item * L<http://www.gnu.org/copyleft/gpl.html>

=back

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=cut