blib/lib/Sys/Utmp.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 50.0% 5 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 82.7% 67 / 81 CC 8 SCAR 10.9
CC
8
Cov
85%
AUTOLOAD
5.2
new
4.6
BEGIN
1.0
CRAP 3.0
« blib/lib/Sys/Utmp/Utent.pm ↑ Summary Utmp.xs »
1 #*****************************************************************************
2 #* *
3 #* Gellyfish Software *
4 #* *
5 #* *
6 #*****************************************************************************
7 #* *
8 #* MODULE : Sys::Utmp *
9 #* *
10 #* AUTHOR : JNS *
11 #* *
12 #* DESCRIPTION : Object(ish) interface to utmp information *
13 #* *
14 #* *
15 #*****************************************************************************
16  
17 package Sys::Utmp;
18  
19 =head1 NAME
20  
21 Sys::Utmp - Object(ish) Interface to UTMP files.
22  
23 =head1 SYNOPSIS
24  
25 use Sys::Utmp;
26  
27 my $utmp = Sys::Utmp->new();
28  
29 while ( my $utent = $utmp->getutent() )
30 {
31 if ( $utent->user_process )
32 {
33 print $utent->ut_user,"\n";
34 }
35 }
36  
37 $utmp->endutent;
38  
39 See also examples/pwho in the distribution directory.
40  
41 =head1 DESCRIPTION
42  
43 Sys::Utmp provides a vaguely object oriented interface to the Unix user
44 accounting file ( sometimes /etc/utmp or /var/run/utmp). Whilst it would
45 prefer to use the getutent() function from the systems C libraries it
46 will attempt to provide its own if they are missing.
47  
48 This may not be the module that you are looking for - there is a User::Utmp
49 which provides a different procedural interface and may well be more complete
50 for your purposes.
51  
52 =head2 METHODS
53  
54 =over 4
55  
56 =item new
57  
58 The constructor of the class. Arguments may be provided in Key => Value
59 pairs : it currently takes one argument 'Filename' which will set the file
60 which is to be used in place of that defined in _PATH_UTMP.
61  
62 =item getutent
63  
64 Iterates of the records in the utmp file returning a Sys::Utmp::Utent object
65 for each record in turn - the methods that are available on these objects
66 are descrived in the L<Sys::Utmp::Utent> documentation. If called in a list
67 context it will return a list containing the elements of th Utent entry
68 rather than an object. If the import flag ':fields' is used then constants
69 defining the indexes into this list will be defined, these are uppercase
70 versions of the methods described in L<Sys::Utmp::Utent>.
71  
72 =item setutent
73  
74 Rewinds the file pointer on the utmp filehandle so repeated searches can be
75 done.
76  
77 =item endutent
78  
79 Closes the file handle on the utmp file.
80  
81 =item utmpname SCALAR filename
82  
83 Sets the file that will be used in place of that defined in _PATH_UTMP.
84 It is not defined what will happen if this is done between two calls to
85 getutent() - it is recommended that endutent() is called first.
86  
87 =back
88  
89 =cut
90  
91 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 7 require Exporter;
96 7 require DynaLoader;
97  
98 7 ▶use base qw(Exporter DynaLoader);
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 BEGIN
101 7 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
102 7 our @constants = qw(
103 ACCOUNTING
104 BOOT_TIME
105 DEAD_PROCESS
106 EMPTY
107 INIT_PROCESS
108 LOGIN_PROCESS
109 NEW_TIME
110 OLD_TIME
111 RUN_LVL
112 USER_PROCESS
113 );
114 }
115  
116 7 ▶use Sys::Utmp::Utent;
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 BEGIN
119 7 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
120 7 our %EXPORT_TAGS = (
121 'constants' => [ @Sys::Utmp::constants ],
122 'fields' => [ @Sys::Utmp::Utent::EXPORT]
123 );
124  
125 7 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'constants'} }, @{ $EXPORT_TAGS{'fields'}} );
126 }
127  
128 7 our $VERSION = '1.8';
129  
130 5 ▶sub new {
Subroutine new: called CC=4 SCAR=15.2
Pod documented
131 5 my ( $proto, %args ) = @_;
132  
133 5 my $self = {};
134 5 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
135 5 bless $self, $class;
136  
137 5 ▶ if ( exists $args{Filename} and -s $args{Filename} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"Filename"} and -s $args{"Filename"}) 0 5 5
Condition66%2/3
exists $args{"Filename"} and -s $args{"Filename"}
!ll&&!rl&&r
320
MC/DC0%0/2
exists $args{"Filename"} and -s $args{"Filename"}
exists $args{"Filename"} -s $args{"Filename"}
Truth table66%2/3
A and B
A= exists $args{"Filename"}B= -s $args{"Filename"}
ABresult
0X0
100
111
138 0 $self->utmpname($args{Filename});
139 }
140 5 return $self;
141 }
142  
143 7 our $AUTOLOAD;
144  
145 10 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=5 SCAR=16.5
146 10 my ( $self ) = @_;
147  
148 10 my $constname;
149 10 ▶ return if $AUTOLOAD =~ /DESTROY/;
Branch: 1 branch
BranchTrueFalseTotal
if $Sys::Utmp::AUTOLOAD =~ /DESTROY/ 0 10 10
150  
151 10 ($constname = $AUTOLOAD) =~ s/.*:://;
152 10 ▶ croak "& not defined" if $constname eq 'constant';
Branch: 1 branch
BranchTrueFalseTotal
if $constname eq "constant" 0 10 10
153 10 ▶ my $val = constant($constname, @_ ? $_[0] : 0);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 10 10
154 10 ▶ if ($! != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($! != 0) 0 10 10
155 0 croak "Your vendor has not defined Sys::Utmp macro $constname";
156 }
157 {
158 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
159 10 ▶ *{$AUTOLOAD} = sub { $val };
Subroutine __ANON__: called CC=1 SCAR=0.0
160 }
161 10 goto &$AUTOLOAD;
162 }
163  
164  
165 7 1;
166  
167 7 bootstrap Sys::Utmp $VERSION;
168  
169 __END__
« blib/lib/Sys/Utmp/Utent.pm ↑ Summary Utmp.xs »