File Coverage

blib/lib/Solaris/Modinfo.pm
Criterion Covered Total %
statement 6 35 17.1
branch 0 2 0.0
condition 0 3 0.0
subroutine 2 6 33.3
pod 3 4 75.0
total 11 50 22.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3             package Solaris::Modinfo;
4              
5 1     1   24998 use strict;
  1         3  
  1         50  
6              
7             require Exporter;
8             require DynaLoader;
9              
10 1     1   5 use vars qw(@ISA $VERSION);
  1         1  
  1         576  
11              
12             @ISA = qw(Exporter DynaLoader);
13              
14             $VERSION = 0.1;
15              
16             sub new {
17 0     0 0   my($proto, @modinfo) = shift;
18 0   0       my $class = ref($proto) || $proto;
19 0           my $self = { };
20              
21 0           @modinfo = qx(modinfo);
22 0           $self->{_private}{numModule} = 0;
23              
24 0           for (@modinfo) {
25 0           chomp;
26 0           s#^\s+##;
27              
28 0 0         next if ($_ =~ /^Id/g);
29 0           my(@line) = split(/\s+/, $_);
30              
31 0           my $id = $self->{_private}{numModule};
32              
33 0           foreach my $info ("Id", "Loadaddr", "Size", "Info", "Rev") {
34 0           $self->{_modinfo}{$id}{$info} = shift(@line);
35             }
36              
37 0           $self->{_modinfo}{$id}{ModuleName} = join(" ", @line);
38 0           $self->{_private}{numModule}++;
39             }
40 0           bless $self, $class;
41            
42 0           return $self;
43             }
44              
45             sub listModule {
46 0     0 1   my($self)= @_;
47              
48 0           return $self->{_modinfo};
49             }
50              
51             sub countModule {
52 0     0 1   my($self)= @_;
53              
54 0           return $self->{_private}{numModule};
55             }
56              
57             sub showModule {
58 0     0 1   my($self) = @_;
59 0           my(@mod_t);
60              
61 0           for (sort { $a <=> $b } keys %{ $self->{_modinfo} }) {
  0            
  0            
62 0           push(@mod_t, $self->{_modinfo}{$_}{Id}, $self->{_modinfo}{$_}{Loadaddr},
63             $self->{_modinfo}{$_}{Size}, $self->{_modinfo}{$_}{Info},
64             $self->{_modinfo}{$_}{Rev}, $self->{_modinfo}{$_}{ModuleName});
65 0           write;
66 0           undef @mod_t;
67             }
68              
69             format STDOUT =
70             @<<<<<@<<<<<<<<<<<@<<<<<<<@<<<<@<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
71             $mod_t[0], $mod_t[1], $mod_t[2], $mod_t[3], $mod_t[4], $mod_t[5]
72             .
73              
74             }
75              
76             1;
77              
78             =head1 NAME
79              
80             Solaris::Modinfo - Perl module providing object oriented interface to modinfo (display information about Solaris loaded kernel modules)
81              
82             =head1 SYNOPSIS
83              
84             use Solaris::Modinfo;
85              
86             my $module = Solaris::Modinfo->new();
87             my $modinfo = $module->listModule();
88              
89             print "Number of modules : ", $module->countModule(), "\n";
90              
91             map {
92             print $modinfo->{$_}{Id}, " ",
93             $modinfo->{$_}{Loadaddr}, " ",
94             $modinfo->{$_}{Size}, " ",
95             $modinfo->{$_}{Info}, " ",
96             $modinfo->{$_}{Rev}, " ",
97             $modinfo->{$_}{ModuleName}, "\n";
98             }(keys %{ $modinfo });
99              
100             =head1 DESCRIPTION
101              
102             This module provides an object oriented interface to the module informations. The implementation attempts to display informations about Solaris loaded kernel modules.
103              
104             =head2 METHODS
105              
106             =item listModule
107              
108             Provide a reference to a hash of the modinfo parameters.
109              
110             =item countModule
111              
112             Display the number of kernel module loaded.
113              
114             =item showModule
115              
116             Display the information of kernel module loaded.
117              
118             =head1 AUTHOR
119              
120             Stephane Chmielewski
121              
122             =head1 COPYRIGHT
123              
124             Copyright (C) 2006 Stephane Chmielewski. All rights reserved.
125             This program is free software; you can redistribute it and/or modify it
126             under the same terms as Perl itself.
127              
128             =cut