File: Device.pm

package info (click to toggle)
libsys-info-base-perl 0.7810-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: perl: 751; makefile: 2; sh: 1
file content (113 lines) | stat: -rw-r--r-- 2,314 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
package Sys::Info::Device;
$Sys::Info::Device::VERSION = '0.7810';
use strict;
use warnings;
use constant SUPPORTED => qw( CPU BIOS );
use Carp qw( croak );
use parent qw( Sys::Info::Base );
use Sys::Info::Constants qw( OSID );

BEGIN {
    MK_ACCESSORS: {
        no strict qw(refs);
        foreach my $device ( SUPPORTED ) {
            *{ '_device_' . lc $device } = sub {
                my $self = shift;
                return  Sys::Info::Base->load_module(
                            'Sys::Info::Device::' . $device
                        )->new(@_);
            }
        }
    }
}

sub new {
    my($class, @args) = @_;
    my $device = shift @args or croak 'Device ID is missing';
    my $self   = {};
    bless $self, $class;

    my $method = '_device_' . lc $device;
    croak "Bogus device ID: $device" if ! $self->can( $method );
    return $self->$method( @args ? @args : () );
}

sub _device_available {
    my $self  = shift;
    my $class = ref $self || $self;
    my @buf;
    local $@;
    local $SIG{__DIE__};

    foreach my $test ( SUPPORTED ) {
        my $eok = eval { $class->new( $test ); 1; };
        next if $@ || ! $eok;
        push @buf, $test;
    }

    return @buf;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Sys::Info::Device

=head1 VERSION

version 0.7810

=head1 SYNOPSIS

    use Sys::Info;
    my $info      = Sys::Info->new;
    my $device    = $info->device( $device_id );
    my @available = $info->device('available');

or

    use Sys::Info::Device;
    my $device    = Sys::Info::Device->new( $device_id );
    my @available = Sys::Info::Device->new('available');

=head1 DESCRIPTION

This is an interface to the available devices such as the C<CPU>.

=head1 NAME

Sys::Info::Device - Information about devices

=head1 METHODS

=head2 new DEVICE_ID

Returns an object to the related device or dies if C<DEVICE_ID> is
bogus or false.

If C<DEVICE_ID> has the value of C<available>, then the names of the
available devices will be returned.

=head1 SEE ALSO

L<Sys::Info::Device::CPU>, L<Sys::Info>.

=head1 AUTHOR

Burak Gursoy

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2006 by Burak Gursoy.

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

=cut