burak / CPAN-Sys-Info-Driver-Unknown

Compatibility layer for Sys::Info (Perl)

commit 0: e059b3c2c086
branch: default
init
Burak Gursoy
13 months ago

Changed (Δ17.3 KB):

raw changeset »

Build.PL (15 lines added, 0 lines removed)

Changes (6 lines added, 0 lines removed)

MANIFEST (15 lines added, 0 lines removed)

META.yml (null-size change)

Makefile.PL (16 lines added, 0 lines removed)

PREREQ (13 lines added, 0 lines removed)

README (33 lines added, 0 lines removed)

lib/Sys/Info/Driver/Unknown.pm (41 lines added, 0 lines removed)

lib/Sys/Info/Driver/Unknown/Device.pm (41 lines added, 0 lines removed)

lib/Sys/Info/Driver/Unknown/Device/CPU.pm (99 lines added, 0 lines removed)

lib/Sys/Info/Driver/Unknown/Device/CPU/Env.pm (311 lines added, 0 lines removed)

lib/Sys/Info/Driver/Unknown/OS.pm (149 lines added, 0 lines removed)

t/01-pod.t (39 lines added, 0 lines removed)

t/02-pod-coverage.t (12 lines added, 0 lines removed)

t/03-basic.t (7 lines added, 0 lines removed)

Up to file-list Build.PL:

1
use strict;
2
use vars qw(%PREREQ %RECOMMEND);
3
4
use Module::Build;
5
6
do 'PREREQ' or die "Error including PREREQ: $@";
7
8
Module::Build->new(
9
   module_name => 'Sys::Info::Driver::Unknown',
10
   license     => 'perl',
11
   requires    => \%PREREQ,
12
   recommends  => \%RECOMMEND,
13
   sign        => 0,
14
   dist_author => 'Burak Gursoy <burak@cpan.org>',
15
)->create_build_script;

Up to file-list Changes:

1
Revision history for Perl extension Sys::Info::Driver::Unknown.
2
3
Time zone is GMT+2.
4
5
0.69_01 Fri Feb 27 05:27:53 2009
6
    => Separation from Sys::Info.

Up to file-list MANIFEST:

1
lib/Sys/Info/Driver/Unknown/Device.pm
2
lib/Sys/Info/Driver/Unknown/OS.pm
3
lib/Sys/Info/Driver/Unknown/Device/CPU.pm
4
lib/Sys/Info/Driver/Unknown/Device/CPU/Env.pm
5
lib/Sys/Info/Driver/Unknown.pm
6
t/01-pod.t
7
t/02-pod-coverage.t
8
t/03-basic.t
9
Makefile.PL
10
Build.PL
11
Changes
12
MANIFEST
13
README
14
PREREQ
15
META.yml

Up to file-list Makefile.PL:

1
use strict;
2
use vars qw(%PREREQ);
3
use ExtUtils::MakeMaker;
4
5
do 'PREREQ' or die "Error including PREREQ: $!";
6
7
WriteMakefile(
8
   'NAME'         => 'Sys::Info::Driver::Unknown',
9
   'VERSION_FROM' => 'lib/Sys/Info/Driver/Unknown.pm',
10
   'PREREQ_PM'    => \%PREREQ,
11
   ($] >= 5.005 ? (
12
   AUTHOR   => 'Burak Gursoy <burak@cpan.org>',
13
   ABSTRACT => 'Compatibility driver for Sys::Info',
14
   ) : ()),
15
   PL_FILES => {},
16
);

Up to file-list PREREQ:

1
#!/usr/bin/perl -w
2
use strict;
3
use vars qw(%PREREQ %RECOMMEND);
4
5
%PREREQ = (
6
   'IO::File'        => 0,
7
   'Test::More'      => '0.40',
8
   'Sys::Info::Base' => '0.69_01',
9
);
10
11
1;
12
13
__END__

Up to file-list README:

1
Sys::Info::Driver::Unknown
2
==========================
3
4
Fetch information about the host system.
5
6
Read the module's POD for documentation.
7
See the tests for examples.
8
9
INSTALLATION
10
11
To install this module type the following:
12
13
   perl Makefile.PL
14
   make
15
   make test
16
   make install
17
18
or under Windows:
19
20
   perl Makefile.PL
21
   nmake
22
   nmake test
23
   nmake install
24
25
COPYRIGHT
26
27
28
29
LICENSE
30
31
This library is free software; you can redistribute it and/or modify 
32
it under the same terms as Perl itself, either Perl version 5.8.8 or, 
33
at your option, any later version of Perl 5 you may have available.

Up to file-list lib/Sys/Info/Driver/Unknown.pm:

1
package Sys::Info::Driver::Unknown;
2
use strict;
3
use vars qw( $VERSION );
4
5
$VERSION = '0.69_01';
6
7
1;
8
9
__END__
10
11
=head1 NAME
12
13
Sys::Info::Driver::Unknown - Compatibility driver for Sys::Info
14
15
=head1 SYNOPSIS
16
17
    use Sys::Info::Driver::Unknown;
18
19
=head1 DESCRIPTION
20
21
This is the main module in the C<Unknown> driver collection.
22
23
=head1 METHODS
24
25
None.
26
27
=head1 AUTHOR
28
29
30
31
=head1 COPYRIGHT
32
33
34
35
=head1 LICENSE
36
37
This library is free software; you can redistribute it and/or modify 
38
it under the same terms as Perl itself, either Perl version 5.8.8 or, 
39
at your option, any later version of Perl 5 you may have available.
40
41
=cut

Up to file-list lib/Sys/Info/Driver/Unknown/Device.pm:

1
package Sys::Info::Driver::Unknown::Device;
2
use strict;
3
use vars qw( $VERSION );
4
5
$VERSION = '0.60';
6
7
1;
8
9
__END__
10
11
=head1 NAME
12
13
Sys::Info::Driver::Unknown::Device - Base class for Unknown device drivers
14
15
=head1 SYNOPSIS
16
17
    use base qw( Sys::Info::Driver::Unknown::Device );
18
19
=head1 DESCRIPTION
20
21
Base class for Unknown device drivers.
22
23
=head1 METHODS
24
25
None.
26
27
=head1 AUTHOR
28
29
30
31
=head1 COPYRIGHT
32
33
34
35
=head1 LICENSE
36
37
This library is free software; you can redistribute it and/or modify 
38
it under the same terms as Perl itself, either Perl version 5.8.8 or, 
39
at your option, any later version of Perl 5 you may have available.
40
41
=cut

Up to file-list lib/Sys/Info/Driver/Unknown/Device/CPU.pm:

1
package Sys::Info::Driver::Unknown::Device::CPU;
2
use strict;
3
use vars qw($VERSION);
4
use base qw(Sys::Info::Driver::Unknown::Device::CPU::Env);
5
6
$VERSION = '0.60';
7
8
BEGIN {
9
    local $SIG{__DIE__};
10
    eval {
11
        require Unix::Processors;
12
        Unix::Processors->import;
13
        1;
14
    };
15
    my $UP = $@ ? 0 : 1;
16
    *_UPOK = sub {$UP};
17
}
18
19
sub load {0}
20
21
sub identify {
22
    my $self = shift;
23
    return $self->_serve_from_cache(wantarray) if $self->{CACHE};
24
25
    my @cpu;
26
    if ( _UPOK ) {
27
        my $up = Unix::Processors->new;
28
        foreach my $proc ( @{ $up->processors } ) {
29
            push @cpu, {
30
31
                data_width                   => undef,
32
                address_width                => undef,
33
                bus_speed                    => undef,
34
                speed                        => $proc->clock,
35
                name                         => $proc->type,
36
                family                       => undef,
37
                manufacturer                 => undef,
38
                model                        => undef,
39
                stepping                     => undef,
40
                number_of_cores              => $up->max_physical,
41
                number_of_logical_processors => $up->max_online,
42
                L1_cache                     => undef,
43
                flags                        => undef,
44
            };
45
        }
46
    } else {
47
        @cpu = $self->SUPER::identify(@_);
48
    }
49
50
    $self->{CACHE} = [ @cpu ];
51
    return $self->_serve_from_cache(wantarray);
52
}
53
54
1;
55
56
__END__
57
58
=head1 NAME
59
60
Sys::Info::Driver::Unknown::Device::CPU - Compatibility layer for unsupported platforms
61
62
=head1 SYNOPSIS
63
64
-
65
66
=head1 DESCRIPTION
67
68
L<Unix::Processors> is recommended for
69
unsupported platforms.
70
71
=head1 METHODS
72
73
=head2 identify
74
75
See identify in L<Sys::Info::Device::CPU>.
76
77
=head2 load
78
79
See load in L<Sys::Info::Device::CPU>.
80
81
=head1 SEE ALSO
82
83
L<Sys::Info>, L<Sys::Info::CPU>, L<Unix::Processors>.
84
85
=head1 AUTHOR
86
87
88
89
=head1 COPYRIGHT
90
91
92
93
=head1 LICENSE
94
95
This library is free software; you can redistribute it and/or modify 
96
it under the same terms as Perl itself, either Perl version 5.8.8 or, 
97
at your option, any later version of Perl 5 you may have available.
98
99
=cut

Up to file-list lib/Sys/Info/Driver/Unknown/Device/CPU/Env.pm:

1
package Sys::Info::Driver::Unknown::Device::CPU::Env;
2
use strict;
3
use vars qw( $VERSION );
4
5
$VERSION = '0.60';
6
7
my(%INTEL, %AMD, %OTHER_ID, %OTHER, %CPU, $INSTALLED);
8
9
sub identify {
10
    my $self = shift;
11
    return $self->_serve_from_cache(wantarray) if $self->{CACHE};
12
    $self->_INSTALL() if not $INSTALLED;
13
14
    if ( not $CPU{id} ) {
15
        $self->{CACHE} = []; # fake
16
        return;
17
    }
18
19
    my($cpu, $count, @cpu);
20
    if ($CPU{id} =~ /(.+?), (?:Genuine(Intel)|Authentic(AMD))/) {
21
        my $cid  = $1;
22
        my $corp = $2 || $3;
23
        if ( my %info = $self->_parse( $cid ) ) {
24
            if ( my $mn = $self->_corp( $corp, $info{Family} ) ) {
25
                if ( my $name = $mn->{ $info{Model} } ) {
26
                    $count = ($CPU{number} && $CPU{number} > 1) ? $CPU{number} : '';
27
                    $cpu   = "$corp $name";
28
                }
29
            }
30
        }
31
    }
32
33
    foreach my $other (keys %OTHER_ID) {
34
        if ($CPU{id} =~ /\Q$other/) {
35
            $cpu = $OTHER_ID{$other};
36
        }
37
    }
38
39
    $count = 1 if not $count;
40
    for ( 1..$count ) {
41
        push @cpu, {
42
            architecture  => ($CPU{id} =~ m{ \A (.+?) \s? Family }xmsi),
43
            data_width    => undef,
44
            speed         => undef,
45
            bus_speed     => undef,
46
            address_width => undef,
47
            name          => $cpu,
48
        };
49
    }
50
    $self->{CACHE} = [@cpu];
51
52
    return $self->_serve_from_cache(wantarray);
53
}
54
55
# ------------------------[ P R I V A T E ]------------------------ #
56
57
sub _INSTALL {
58
    my $self   = shift;
59
    %INTEL     = _INTEL();
60
    %AMD       = _AMD();
61
    %OTHER_ID  = _OTHER_ID();
62
    %OTHER     = _OTHER();
63
    %CPU       = (                              # PIV 3.0 GHz HT
64
        id     => $ENV{PROCESSOR_IDENTIFIER},   # x86 Family 15 Model 3 Stepping 3, GenuineIntel
65
        number => $ENV{NUMBER_OF_PROCESSORS},   # 2
66
        arch   => $ENV{PROCESSOR_ARCHITECTURE}, # x86
67
        rev    => $ENV{PROCESSOR_REVISION},     # 0303
68
        level  => $ENV{PROCESSOR_LEVEL},        # 15
69
    );
70
71
    if ( ! $CPU{id} && $self->can('__env_pi') ) {
72
        $CPU{id} = $self->__env_pi;
73
    }
74
    $INSTALLED = 1;
75
}
76
77
sub _corp {
78
    my $self   = shift;
79
    my $corp   = shift;
80
    my $family = shift;
81
    return $INTEL{$family} if $corp eq 'Intel';
82
    return $AMD{$family}   if $corp eq 'AMD';
83
}
84
85
sub _parse {
86
    my $self = shift;
87
    my $id   = shift;
88
    my $arch = $CPU{arch};
89
    if ($id =~ /$arch\s(.+?)$/) {
90
        my %h = split /\s+/, $1; # Family Model Stepping
91
        for my $k (keys %h) {
92
            $h{$k} = '' unless defined $h{$k};
93
        }
94
        return %h;
95
    }
96
}
97
98
sub _INTEL {
99
   # Family  Model    Name
100
    4  => {
101
            0     => '486 DX-25/33',
102
            1     => '486 DX-50',
103
            2     => '486 SX',
104
            3     => '486 DX/2',
105
            4     => '486 SL',
106
            5     => '486 SX/2',
107
            7     => '486 DX/2-WB',
108
            8     => '486 DX/4',
109
            9     => '486 DX/4-WB',
110
    },
111
    5  => {
112
            0     => 'Pentium 60/66 A-step',
113
            1     => 'Pentium 60/66',
114
            2     => 'Pentium 75 - 200',
115
            3     => 'OverDrive PODP5V83',
116
            4     => 'Pentium MMX',
117
            7     => 'Mobile Pentium 75 - 200',
118
            8     => 'Mobile Pentium MMX',
119
    },
120
    6  => {
121
            0     => 'Pentium Pro A-step',
122
            1     => 'Pentium Pro',
123
            3     => 'Pentium II (Klamath)',
124
            5     => 'Pentium II (Deschutes), Celeron (Covington), Mobile Pentium II (Dixon)',
125
            6     => 'Mobile Pentium II, Celeron (Mendocino)',
126
            7     => 'Pentium III (Katmai)',
127
            8     => 'Pentium III (Coppermine)',
128
            9     => 'Mobile Pentium III',
129
130
131
132
            13    => 'Celeron M', # ???
133
            15    => 'Core 2 Duo (Merom)', # ???
134
    },
135
    7  => {
136
            0     => 'Itanium (IA-64)',
137
    },
138
    15 => {
139
140
141
142
143
            # Itanium 2 (IA-64)?
144
    },
145
}
146
147
sub _AMD {
148
    # Family  Model    Name
149
    4  => {
150
        3     => '486 DX/2',
151
        7     => '486 DX/2-WB',
152
        8     => '486 DX/4',
153
        9     => '486 DX/4-WB',
154
        14    => 'Am5x86-WT',
155
        15    => 'Am5x86-WB',
156
    },
157
    5  => {
158
        0     => 'K5/SSA5',
159
        1     => 'K5',
160
        2     => 'K5',
161
        3     => 'K5',
162
        6     => 'K6',
163
        7     => 'K6',
164
        8     => 'K6-2',
165
        9     => 'K6-3',
166
        13    => 'K6-2+ or K6-III+',
167
    },
168
    6  => {
169
170
171
172
        3     => 'Duron',
173
        4     => 'Athlon (Thunderbird)',
174
        6     => 'Athlon (Palamino)',
175
        7     => 'Duron (Morgan)',
176
        8     => 'Athlon (Thoroughbred)',
177
        10    => 'Athlon (Barton)',
178
    },
179
    15 => {
180
        4     => 'Athlon 64',
181
        5     => 'Athlon 64 FX Opteron',
182
    },
183
}
184
185
sub _OTHER_ID {
186
    # Vendor          Manufacturer Name
187
    'CyrixInstead' => 'Cyrix',
188
    'CentaurHauls' => 'Centaur',
189
    'NexGenDriven' => 'NexGen',
190
    'GenuineTMx86' => 'Transmeta',
191
    'RiseRiseRise' => 'Rise',
192
    'UMC UMC UMC'  => 'UMC',
193
    'SiS SiS SiS'  => 'SiS',
194
    'Geode by NSC' => 'National Semiconductor',
195
}
196
197
sub _OTHER {
198
    Cyrix => {
199
    # Family Model Name
200
        4 => {
201
            4 => 'MediaGX',
202
        },
203
        5 => {
204
            2 => '6x86 / 6x86L (Identifying the difference)',
205
            4 => 'MediaGX MMX Enhanced',
206
        },
207
        6 => {
208
            0 => 'm II (6x86MX)',
209
            5 => 'VIA Cyrix M2 core',
210
            6 => 'WinChip C5A',
211
            7 => 'WinChip C5B ,WinChip C5C',
212
            8 => 'WinChip C5N',
213
            9 => 'WinChip C5XL, WinChip C5P',
214
        },
215
    },
216
    UMC => {
217
        4 => {
218
            1 => 'U5D',
219
            2 => 'U5S',
220
        },
221
    },
222
    Centaur => {
223
        5 => {
224
            4 => 'C6',
225
            8 => 'C2',
226
            9 => 'C3',
227
        },
228
    },
229
    'National Semiconductor' => {
230
        5 => {
231
            4 => 'GX1, GXLV, GXm',
232
            5 => 'GX2',
233
        },
234
    },
235
236
    NexGen => {
237
        5 => {
238
            0 => 'Nx586',
239
        },
240
    },
241
    Rise => {
242
        5 => {
243
            0 => 'mP6',
244
            1 => 'mP6',
245
        },
246
    },
247
    SiS => {
248
        5 => {
249
            0 => '55x',
250
        }
251
    },
252
    Transmeta => {
253
        5 => {
254
            4 => 'Crusoe TM3x00 and TM5x00',
255
        },
256
    },
257
}
258
259
1;
260
261
__END__
262
263
=head1 NAME
264
265
Sys::Info::Driver::Unknown::Device::CPU::Env - Fetch CPU information from %ENV
266
267
=head1 SYNOPSIS
268
269
Nothing public here.
270
271
=head1 DESCRIPTION
272
273
These C<%ENV> keys are recognised by this module:
274
275
   PROCESSOR_IDENTIFIER
276
   NUMBER_OF_PROCESSORS
277
   PROCESSOR_ARCHITECTURE
278
   PROCESSOR_REVISION
279
   PROCESSOR_LEVEL
280
281
=head1 METHODS
282
283
=head2 identify
284
285
See identify in L<Sys::Info::Device::CPU>.
286
287
=head2 load
288
289
See load in L<Sys::Info::Device::CPU>.
290
291
=head1 SEE ALSO
292
293
L<Sys::Info>,
294
L<http://www.sandpile.org/>,
295
L<http://www.paradicesoftware.com/specs/cpuid/index.htm>.
296
297
=head1 AUTHOR
298
299
300
301
=head1 COPYRIGHT
302
303
304
305
=head1 LICENSE
306
307
This library is free software; you can redistribute it and/or modify 
308
it under the same terms as Perl itself, either Perl version 5.8.8 or, 
309
at your option, any later version of Perl 5 you may have available.
310
311
=cut

Up to file-list lib/Sys/Info/Driver/Unknown/OS.pm:

1
package Sys::Info::Driver::Unknown::OS;
2
use strict;
3
use vars qw( $VERSION );
4
use POSIX ();
5
use Sys::Info::Constants qw( :unknown );
6
7
$VERSION = '0.60';
8
9
# So, we don't support $^O yet, but we can try to emulate some features
10
11
BEGIN {
12
    *is_root     = *uptime
13
                 = *tick_count
14
                 = sub { 0 }
15
                 ;
16
    *domain_name = *edition
17
                 = *logon_server
18
                 = sub {   }
19
                 ;
20
}
21
22
sub meta {
23
    my $self = shift;
24
    my %info;
25
26
    $info{manufacturer}              = undef;
27
    $info{build_type}                = undef;
28
    $info{owner}                     = undef;
29
    $info{organization}              = undef;
30
    $info{product_id}                = undef;
31
    $info{install_date}              = undef;
32
    $info{boot_device}               = undef;
33
    $info{physical_memory_total}     = undef;
34
    $info{physical_memory_available} = undef;
35
    $info{page_file_total}           = undef;
36
    $info{page_file_available}       = undef;
37
    # windows specific
38
    $info{windows_dir}               = undef;
39
    $info{system_dir}                = undef;
40
    $info{system_manufacturer}       = undef;
41
    $info{system_model}              = undef;
42
    $info{system_type}               = undef;
43
    $info{page_file_path}            = undef;
44
45
    return %info;
46
}
47
48
sub tz {
49
    my $self = shift;
50
    return exists $ENV{TZ} ? $ENV{TZ} : undef;
51
}
52
53
sub fs { +() }
54
55
sub name {
56
    my $self  = shift;
57
    my %opt   = @_ % 2 ? () : (@_);
58
    my @uname = POSIX::uname();
59
    my $rv    = $opt{long} ? join(' ', @uname[UN_OS_SYSNAME, UN_OS_RELEASE])
60
              :              $uname[UN_OS_SYSNAME]
61
              ;
62
    return $rv;
63
}
64
65
sub version { (POSIX::uname)[UN_OS_RELEASE] }
66
67
sub build {
68
    my $build = (POSIX::uname)[UN_OS_VERSION] || return;
69
    if ( $build =~ UN_RE_BUILD ) {
70
        return $1;
71
    }
72
    return $build;
73
}
74
75
sub node_name { (POSIX::uname)[UN_OS_NODENAME] }
76
77
sub login_name {
78
    my $name;
79
    eval { $name = getlogin() };
80
    return $name;
81
}
82
83
1;
84
85
__END__
86
87
=head1 NAME
88
89
Sys::Info::Driver::Unknown::OS - Compatibility layer for unsupported platforms
90
91
=head1 SYNOPSIS
92
93
-
94
95
=head1 DESCRIPTION
96
97
-
98
99
=head1 METHODS
100
101
Please see L<Sys::Info::OS> for definitions of these methods and more.
102
103
=head2 build
104
105
=head2 domain_name
106
107
=head2 edition
108
109
=head2 fs
110
111
=head2 is_root
112
113
=head2 login_name
114
115
=head2 logon_server
116
117
=head2 meta
118
119
=head2 name
120
121
=head2 node_name
122
123
=head2 tick_count
124
125
=head2 tz
126
127
=head2 uptime
128
129
=head2 version
130
131
=head1 SEE ALSO
132
133
L<Sys::Info>, L<Sys::Info::OS>.
134
135
=head1 AUTHOR
136
137
138
139
=head1 COPYRIGHT
140
141
142
143
=head1 LICENSE
144
145
This library is free software; you can redistribute it and/or modify 
146
it under the same terms as Perl itself, either Perl version 5.8.8 or, 
147
at your option, any later version of Perl 5 you may have available.
148
149
=cut

Up to file-list t/01-pod.t:

1
#!/usr/bin/env perl -w
2
use strict;
3
use Test::More;
4
5
my @errors;
6
eval { require Test::Pod; };
7
push @errors, "Test::Pod is required for testing POD"   if $@;
8
eval { require Pod::Simple; };
9
push @errors, "Pod::Simple is required for testing POD" if $@;
10
11
if ( not @errors ) {
12
   my $tpv = $Test::Pod::VERSION;
13
   my $psv = $Pod::Simple::VERSION;
14
15
   if ( $tpv < 1.26 ) {
16
      push @errors, "Upgrade Test::Pod to 1.26 to run this test. "
17
                   ."Detected version is: $tpv";
18
   }
19
20
   if ( $psv < 3.05 ) {
21
      push @errors, "Upgrade Pod::Simple to 3.05 to run this test. "
22
                   ."Detected version is: $psv";
23
   }
24
}
25
26
if ( $] < 5.008 ) {
27
   # Any older perl does not have Encode.pm. Thus, Pod::Simple
28
   # can not handle utf8 encoding and it will die, the tests
29
   # will fail. This skip part, skips an inevitable failure.
30
   push @errors, "'=encoding utf8' directives in Pods don't work "
31
                ."with legacy perl.";
32
}
33
34
if ( @errors ) {
35
   plan skip_all => "Errors detected: @errors";
36
}
37
else {
38
   Test::Pod::all_pod_files_ok();
39
}

Up to file-list t/02-pod-coverage.t:

1
#!/usr/bin/env perl -w
2
use strict;
3
use Test::More;
4
5
eval q{use Test::Pod::Coverage; 1;};
6
7
if ( $@ ) {
8
    plan skip_all => "Test::Pod::Coverage required for testing pod coverage";
9
}
10
else {
11
   all_pod_coverage_ok();
12
}

Up to file-list t/03-basic.t:

1
#!/usr/bin/env perl -w
2
use strict;
3
use Test::More qw( no_plan );
4
5
ok(1);
6
7
1;