burak / CPAN-Sys-Info-Driver-BSD

BSD driver for Sys::Info (Perl)

Changed (Δ1.5 KB):

raw changeset »

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

Changes (3 lines added, 1 lines removed)

SPEC (1 lines added, 0 lines removed)

lib/Sys/Info/Driver/BSD.pm (4 lines added, 18 lines removed)

lib/Sys/Info/Driver/BSD/Device.pm (1 lines added, 14 lines removed)

lib/Sys/Info/Driver/BSD/Device/CPU.pm (1 lines added, 14 lines removed)

lib/Sys/Info/Driver/BSD/OS.pm (19 lines added, 31 lines removed)

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

Up to file-list Build.PL:

1
1
use strict;
2
use warnings;
2
3
use lib qw( builder );
3
4
use Build;
4
5
5
6
my $mb = Build->new;
6
7
$mb->change_versions(1);
8
$mb->copyright_first_year( '2009' );
9
$mb->add_pod_author_copyright_license(1);
7
10
$mb->create_build_script;
11
12
1;

Up to file-list Changes:

@@ -2,8 +2,10 @@ Revision history for Perl extension Sys:
2
2
3
3
Time zone is GMT+2.
4
4
5
0.73 Sun Jun  7 03:12:44 2009
5
0.73 Tue Dec 15 07:35:30 2009
6
6
    => Support new uname().
7
    => Perl::Critic refactoring.
8
7
9
0.72 Sun May  3 03:30:41 2009
8
10
    => Update builder.
9
11

Up to file-list SPEC:

@@ -8,6 +8,7 @@ die "OS unsupported\n" if ! $OK;
8
8
        'BSD::Sysctl'      => '0.08',
9
9
        'Unix::Processors' => 0,
10
10
        'Sys::Info::Base'  => '0.72',
11
        ($] < 5.006 ? ( 'warnings::compat' => 0 ) : ()),
11
12
    },
12
13
    build_requires => {
13
14
        'Test::Sys::Info'  => '0.15',

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

1
1
package Sys::Info::Driver::BSD;
2
2
use strict;
3
use warnings;
3
4
use vars qw( $VERSION @ISA @EXPORT );
4
5
use BSD::Sysctl qw( sysctl sysctl_exists );
5
use Exporter ();
6
use base qw( Exporter );
6
7
use Carp qw( croak );
7
8
8
9
$VERSION = '0.73';
9
@ISA     = qw( Exporter );
10
10
@EXPORT  = qw( fsysctl nsysctl );
11
11
12
12
sub fsysctl {
13
    my $key = shift || croak "Key is missing";
13
    my $key = shift || croak 'Key is missing';
14
14
    my $val = sysctl_exists($key) ? sysctl($key)
15
15
                                  : croak "Can not happen: $key is not defined";
16
16
    return $val;
17
17
}
18
18
19
19
sub nsysctl {
20
    my $key = shift || croak "Key is missing";
20
    my $key = shift || croak 'Key is missing';
21
21
    return if ! sysctl_exists($key);
22
22
    return sysctl($key);
23
23
}
@@ -52,18 +52,4 @@ f(atal)sysctl(). Implemented via L<BSD::
52
52
53
53
n(ormal)sysctl. Implemented via L<BSD::Sysctl>.
54
54
55
=head1 AUTHOR
56
57
Burak Gürsoy, E<lt>burakE<64>cpan.orgE<gt>
58
59
=head1 COPYRIGHT
60
61
Copyright 2009 Burak Gürsoy. All rights reserved.
62
63
=head1 LICENSE
64
65
This library is free software; you can redistribute it and/or modify 
66
it under the same terms as Perl itself, either Perl version 5.10.0 or, 
67
at your option, any later version of Perl 5 you may have available.
68
69
55
=cut

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

1
1
package Sys::Info::Driver::BSD::Device;
2
2
use strict;
3
use warnings;
3
4
use vars qw( $VERSION );
4
5
5
6
$VERSION = '0.70';
@@ -24,18 +25,4 @@ Base class for BSD device drivers.
24
25
25
26
None.
26
27
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.10.0 or, 
39
at your option, any later version of Perl 5 you may have available.
40
41
28
=cut

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

1
1
package Sys::Info::Driver::BSD::Device::CPU;
2
2
use strict;
3
use warnings;
3
4
use vars qw($VERSION);
4
5
use base qw(Sys::Info::Base);
5
6
use Unix::Processors;
@@ -99,18 +100,4 @@ L<Sys::Info>,
99
100
L<Sys::Info::Device::CPU>,
100
101
L<Unix::Processors>, L<POSIX>.
101
102
102
=head1 AUTHOR
103
104
Burak Gürsoy, E<lt>burakE<64>cpan.orgE<gt>
105
106
=head1 COPYRIGHT
107
108
Copyright 2009 Burak Gürsoy. All rights reserved.
109
110
=head1 LICENSE
111
112
This library is free software; you can redistribute it and/or modify 
113
it under the same terms as Perl itself, either Perl version 5.10.0 or, 
114
at your option, any later version of Perl 5 you may have available.
115
116
103
=cut

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

1
1
package Sys::Info::Driver::BSD::OS;
2
2
use strict;
3
use warnings;
3
4
use vars qw( $VERSION );
4
5
use base qw( Sys::Info::Base );
5
6
use POSIX ();
@@ -23,12 +24,12 @@ sub logon_server {}
23
24
24
25
sub edition {
25
26
    my $self = shift->_populate_osversion;
26
    $OSVERSION{RAW}->{EDITION};
27
    return $OSVERSION{RAW}->{EDITION};
27
28
}
28
29
29
30
sub tz {
30
31
    my $self = shift;
31
    return POSIX::strftime("%Z", localtime);
32
    return POSIX::strftime('%Z', localtime);
32
33
}
33
34
34
35
sub meta {
@@ -63,7 +64,7 @@ sub meta {
63
64
64
65
    $info{system_manufacturer}       = undef;
65
66
    $info{system_model}              = undef;
66
    $info{system_type}               = sprintf "%s based Computer", $arch;
67
    $info{system_type}               = sprintf '%s based Computer', $arch;
67
68
68
69
    $info{page_file_path}            = undef;
69
70
@@ -76,8 +77,9 @@ sub tick_count {
76
77
}
77
78
78
79
sub name {
79
    my $self = shift->_populate_osversion;
80
    my %opt  = @_ % 2 ? () : (@_);
80
    my($self, @args) = @_;
81
    $self->_populate_osversion;
82
    my %opt  = @args % 2 ? () : @args;
81
83
    my $id   = $opt{long} ? ($opt{edition} ? 'LONGNAME_EDITION' : 'LONGNAME')
82
84
             :              ($opt{edition} ? 'NAME_EDITION'     : 'NAME'    )
83
85
             ;
@@ -95,32 +97,31 @@ sub is_root {
95
97
    my $id   = POSIX::geteuid();
96
98
    my $gid  = POSIX::getegid();
97
99
    return 0 if $@;
98
    return 0 if ! defined($id) || ! defined($gid);
100
    return 0 if ! defined $id || ! defined $gid;
99
101
    return $id == 0 && $gid == 0; # && $name eq 'root'; # $name is never root!
100
102
}
101
103
102
104
sub login_name {
103
    my $self  = shift;
104
    my %opt   = @_ % 2 ? () : (@_);
105
    my($self, @args) = @_;
106
    my %opt   = @args % 2 ? () : @args;
105
107
    my $login = POSIX::getlogin() || return;
106
108
    my $rv    = eval { $opt{real} ? (getpwnam $login)[LIN_REAL_NAME_FIELD] : $login };
107
109
    $rv =~ s{ [,]{3,} \z }{}xms if $opt{real};
108
110
    return $rv;
109
111
}
110
112
111
sub node_name { shift->uname->{nodename} }
113
sub node_name { return shift->uname->{nodename} }
112
114
113
115
sub domain_name { }
114
116
115
117
sub fs {
116
118
    my $self = shift;
117
    return(
118
        unimplemented => 1,
119
    );
119
    return unimplemented => 1;
120
120
}
121
121
122
122
sub bitness {
123
123
    my $self = shift;
124
    return;
124
125
}
125
126
126
127
# ------------------------[ P R I V A T E ]------------------------ #
@@ -131,6 +132,7 @@ sub _file_has_substr {
131
132
    my $str  = shift;
132
133
    return if ! -e $file || ! -f _;
133
134
    my $raw = $self->slurp( $file ) =~ m{$str}xms;
135
    return $raw;
134
136
}
135
137
136
138
sub _probe_edition {
@@ -156,7 +158,7 @@ sub _populate_osversion {
156
158
    require POSIX;
157
159
    my($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
158
160
159
    my(undef, $raw)  = split m{[#]}, $version;
161
    my(undef, $raw)  = split m{\#}xms, $version;
160
162
    my($date, undef) = split m{ \s+ \S+ \z }xms, $raw;
161
163
    my $build_date = $date ? $self->date2time( $date ) : undef;
162
164
    my $build      = $date;
@@ -167,8 +169,8 @@ sub _populate_osversion {
167
169
    %OSVERSION = (
168
170
        NAME             => $sysname,
169
171
        NAME_EDITION     => $edition ? "$sysname ($edition)" : $sysname,
170
        LONGNAME         => '', # will be set below
171
        LONGNAME_EDITION => '', # will be set below
172
        LONGNAME         => q{}, # will be set below
173
        LONGNAME_EDITION => q{}, # will be set below
172
174
        VERSION  => $release,
173
175
        KERNEL   => undef,
174
176
        RAW      => {
@@ -178,10 +180,10 @@ sub _populate_osversion {
178
180
                    },
179
181
    );
180
182
181
    $OSVERSION{LONGNAME}         = sprintf "%s %s (kernel: %s)",
183
    $OSVERSION{LONGNAME}         = sprintf '%s %s (kernel: %s)',
182
184
                                   @OSVERSION{ qw/ NAME         VERSION / },
183
185
                                   $kernel;
184
    $OSVERSION{LONGNAME_EDITION} = sprintf "%s %s (kernel: %s)",
186
    $OSVERSION{LONGNAME_EDITION} = sprintf '%s %s (kernel: %s)',
185
187
                                   @OSVERSION{ qw/ NAME_EDITION VERSION / },
186
188
                                   $kernel;
187
189
    return;
@@ -243,18 +245,4 @@ L<Sys::Info>, L<Sys::Info::OS>,
243
245
The C</proc> virtual filesystem:
244
246
L<http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-proc-topfiles.html>.
245
247
246
=head1 AUTHOR
247
248
Burak Gürsoy, E<lt>burakE<64>cpan.orgE<gt>
249
250
=head1 COPYRIGHT
251
252
Copyright 2006-2009 Burak Gürsoy. All rights reserved.
253
254
=head1 LICENSE
255
256
This library is free software; you can redistribute it and/or modify 
257
it under the same terms as Perl itself, either Perl version 5.10.0 or, 
258
at your option, any later version of Perl 5 you may have available.
259
260
248
=cut

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

1
1
#!/usr/bin/env perl -w
2
2
use strict;
3
use warnings;
3
4
use Test::Sys::Info;
4
5
5
6
driver_ok('BSD');