File Coverage

blib/lib/Archive/Tar/Builder/UserCache.pm
Criterion Covered Total %
statement 18 18 100.0
branch 8 8 100.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 30 32 93.7


line stmt bran cond sub pod time code
1             # Copyright (c) 2012, cPanel, Inc.
2             # All rights reserved.
3             # http://cpanel.net/
4             #
5             # This is free software; you can redistribute it and/or modify it under the same
6             # terms as Perl itself. See the LICENSE file for further details.
7              
8             package Archive::Tar::Builder::UserCache;
9              
10 8     8   452 use strict;
  8         20  
  8         205  
11 8     8   32 use warnings;
  8         9  
  8         1565  
12              
13             sub new {
14 92     92 0 13579409 my ($class) = @_;
15              
16 92         1704 return bless {
17             'users' => {},
18             'groups' => {}
19             }, $class;
20             }
21              
22             sub lookup {
23 6672     6672 0 661031 my ( $self, $uid, $gid ) = @_;
24              
25 6672 100       21489 unless ( exists $self->{'users'}->{$uid} ) {
26 45 100       9509 if ( my @pwent = getpwuid($uid) ) {
27 44         537 $self->{'users'}->{$uid} = $pwent[0];
28             }
29             else {
30 1         4 $self->{'users'}->{$uid} = undef;
31             }
32             }
33              
34 6672 100       14968 unless ( exists $self->{'groups'}->{$gid} ) {
35 45 100       2455 if ( my @grent = getgrgid($gid) ) {
36 44         293 $self->{'groups'}->{$gid} = $grent[0];
37             }
38             else {
39 1         4 $self->{'groups'}->{$gid} = undef;
40             }
41             }
42              
43 6672         1133476 return ( $self->{'users'}->{$uid}, $self->{'groups'}->{$gid} );
44             }
45              
46             1;