| 1 | package Sys::Group::GIDhelper; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | Sys::Group::GIDhelper - Helps for locating free GIDs using getgrgid. | ||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | =head1 VERSION | ||||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | Version 0.1.0 | ||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | =cut | ||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 1 | our $VERSION = '0.1.0'; | |||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | use Sys::Group::GIDhelper; | ||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | # invokes it with the default values | ||||||||||||||||||
| 23 | my $foo = Sys::Group::GIDhelper->new(); | ||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | # sets the min to 2000 and the max to 4000 | ||||||||||||||||||
| 26 | my $foo = Sys::Group::GIDhelper->new(min=>2000, max=>4000); | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | # finds the first free one | ||||||||||||||||||
| 29 | my $first = $foo->firstfree(); | ||||||||||||||||||
| 30 | if(defined($first)){ | ||||||||||||||||||
| 31 | print $first."\n"; | ||||||||||||||||||
| 32 | }else{ | ||||||||||||||||||
| 33 | print "not found\n"; | ||||||||||||||||||
| 34 | } | ||||||||||||||||||
| 35 | |||||||||||||||||||
| 36 | # finds the last free one | ||||||||||||||||||
| 37 | my $last = $foo->lastfree(); | ||||||||||||||||||
| 38 | if(defined($last)){ | ||||||||||||||||||
| 39 | print $last."\n"; | ||||||||||||||||||
| 40 | }else{ | ||||||||||||||||||
| 41 | print "not found\n"; | ||||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | =head1 METHODS | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | =head2 new | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | This initiates the module. The following args are accepted. | ||||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | - min :: The GID to start with. | ||||||||||||||||||
| 51 | - Default :: 1000 | ||||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | - max :: The last GID in the range to check for. | ||||||||||||||||||
| 54 | - Default :: 131068 | ||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | The following is a example showing showing a new instance being created | ||||||||||||||||||
| 57 | that will start at 2000 and search up to 4000. | ||||||||||||||||||
| 58 | |||||||||||||||||||
| 59 | my $foo = Sys::Group::GIDhelper->new(min=>2000, max=>4000); | ||||||||||||||||||
| 60 | |||||||||||||||||||
| 61 | If any of the args are non-integers or min is greater than max, it will error. | ||||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | =cut | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | 0 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||
| 66 | 0 | my ( $blank, %args ) = @_; | |||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | 0 | ▶ | if ( !defined( $args{max} ) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 69 | 0 | $args{max} = 131068; | |||||||||||||||||
| 70 | } | ||||||||||||||||||
| 71 | # this is choosen as on most systems 1000 is the general base for new | ||||||||||||||||||
| 72 | 0 | ▶ | if ( !defined( $args{min} ) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 73 | 0 | $args{min} = 1000; | |||||||||||||||||
| 74 | } | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | # max sure the values we got passed are sane | ||||||||||||||||||
| 77 | 0 | ▶ | if ( $args{min} >= $args{max} ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 78 | 0 | die( 'min, ' . $args{min} . ', is equal to or greater than max, ' . $args{max} . ',' ); | |||||||||||||||||
| 79 | } elsif ( $args{min} !~ /^[0-9]+$/ ) { | ||||||||||||||||||
| 80 | 0 | die( 'min, "' . $args{min} . '", is not numeric' ); | |||||||||||||||||
| 81 | } elsif ( $args{max} !~ /^[0-9]+$/ ) { | ||||||||||||||||||
| 82 | 0 | die( 'min, "' . $args{max} . '", is not numeric' ); | |||||||||||||||||
| 83 | } | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | my $self = { | ||||||||||||||||||
| 86 | max => $args{max}, | ||||||||||||||||||
| 87 | min => $args{min}, | ||||||||||||||||||
| 88 | 0 | }; | |||||||||||||||||
| 89 | 0 | bless $self; | |||||||||||||||||
| 90 | |||||||||||||||||||
| 91 | 0 | return $self; | |||||||||||||||||
| 92 | } ## end sub new | ||||||||||||||||||
| 93 | |||||||||||||||||||
| 94 | =head2 first_free | ||||||||||||||||||
| 95 | |||||||||||||||||||
| 96 | This finds the first free GID. If it returns undef, no free ones were found. | ||||||||||||||||||
| 97 | |||||||||||||||||||
| 98 | =cut | ||||||||||||||||||
| 99 | |||||||||||||||||||
| 100 | 0 | ▶ | sub first_free { | ||||||||||||||||
|
Subroutine
first_free: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 101 | 0 | my $self = $_[0]; | |||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | 0 | my $int = $self->{min}; | |||||||||||||||||
| 104 | 0 | ▶ | while ( $int <= $self->{max} ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 105 | 0 | ▶ | if ( !getgrgid($int) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 106 | 0 | return $int; | |||||||||||||||||
| 107 | } | ||||||||||||||||||
| 108 | |||||||||||||||||||
| 109 | 0 | $int++; | |||||||||||||||||
| 110 | } | ||||||||||||||||||
| 111 | |||||||||||||||||||
| 112 | 0 | return undef; | |||||||||||||||||
| 113 | } ## end sub first_free | ||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | =head2 firstfree | ||||||||||||||||||
| 116 | |||||||||||||||||||
| 117 | An alias of firstfree to remain compatible with v. 0.0.2. | ||||||||||||||||||
| 118 | |||||||||||||||||||
| 119 | =cut | ||||||||||||||||||
| 120 | |||||||||||||||||||
| 121 | 0 | ▶ | sub firstfree { | ||||||||||||||||
|
Subroutine
firstfree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 122 | 0 | return $_[0]->first_free; | |||||||||||||||||
| 123 | } | ||||||||||||||||||
| 124 | |||||||||||||||||||
| 125 | =head2 lastfree | ||||||||||||||||||
| 126 | |||||||||||||||||||
| 127 | This finds the first last UID. If it returns undef, no free ones were found. | ||||||||||||||||||
| 128 | |||||||||||||||||||
| 129 | =cut | ||||||||||||||||||
| 130 | |||||||||||||||||||
| 131 | 0 | ▶ | sub last_free { | ||||||||||||||||
|
Subroutine
last_free: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||
| 132 | 0 | my $self = $_[0]; | |||||||||||||||||
| 133 | |||||||||||||||||||
| 134 | 0 | my $int = $self->{max}; | |||||||||||||||||
| 135 | 0 | ▶ | while ( $int >= $self->{min} ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 136 | 0 | ▶ | if ( !getgrgid($int) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 137 | 0 | return $int; | |||||||||||||||||
| 138 | } | ||||||||||||||||||
| 139 | |||||||||||||||||||
| 140 | 0 | $int--; | |||||||||||||||||
| 141 | } | ||||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | 0 | return undef; | |||||||||||||||||
| 144 | } ## end sub last_free | ||||||||||||||||||
| 145 | |||||||||||||||||||
| 146 | =head2 lastfree | ||||||||||||||||||
| 147 | |||||||||||||||||||
| 148 | An alias of lastfree to remain compatible with v. 0.0.1. | ||||||||||||||||||
| 149 | |||||||||||||||||||
| 150 | =cut | ||||||||||||||||||
| 151 | |||||||||||||||||||
| 152 | 0 | ▶ | sub lastfree { | ||||||||||||||||
|
Subroutine
lastfree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 153 | 0 | return $_[0]->last_free; | |||||||||||||||||
| 154 | } | ||||||||||||||||||
| 155 | |||||||||||||||||||
| 156 | #=head2 errorBlank | ||||||||||||||||||
| 157 | |||||||||||||||||||
| 158 | =head1 AUTHOR | ||||||||||||||||||
| 159 | |||||||||||||||||||
| 160 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||||||||||
| 161 | |||||||||||||||||||
| 162 | =head1 BUGS | ||||||||||||||||||
| 163 | |||||||||||||||||||
| 164 | Please report any bugs or feature requests to C<bug-sys-group-gidhelper at rt.cpan.org>, or through | ||||||||||||||||||
| 165 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Group-UIDhelper>. I will be notified, and then you'll | ||||||||||||||||||
| 166 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||
| 167 | |||||||||||||||||||
| 168 | |||||||||||||||||||
| 169 | |||||||||||||||||||
| 170 | |||||||||||||||||||
| 171 | =head1 SUPPORT | ||||||||||||||||||
| 172 | |||||||||||||||||||
| 173 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||
| 174 | |||||||||||||||||||
| 175 | perldoc Sys::Group::GIDhelper | ||||||||||||||||||
| 176 | |||||||||||||||||||
| 177 | |||||||||||||||||||
| 178 | You can also look for information at: | ||||||||||||||||||
| 179 | |||||||||||||||||||
| 180 | =over 4 | ||||||||||||||||||
| 181 | |||||||||||||||||||
| 182 | =item * RT: CPAN's request tracker | ||||||||||||||||||
| 183 | |||||||||||||||||||
| 184 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Group-GIDhelper> | ||||||||||||||||||
| 185 | |||||||||||||||||||
| 186 | =item * Search CPAN | ||||||||||||||||||
| 187 | |||||||||||||||||||
| 188 | L<https://metacpan.org/dist/Sys-Group-GIDhelper> | ||||||||||||||||||
| 189 | |||||||||||||||||||
| 190 | =back | ||||||||||||||||||
| 191 | |||||||||||||||||||
| 192 | |||||||||||||||||||
| 193 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||
| 194 | |||||||||||||||||||
| 195 | |||||||||||||||||||
| 196 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||
| 197 | |||||||||||||||||||
| 198 | Copyright 2023 Zane C. Bowers, all rights reserved. | ||||||||||||||||||
| 199 | |||||||||||||||||||
| 200 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||
| 201 | under the same terms as Perl itself. | ||||||||||||||||||
| 202 | |||||||||||||||||||
| 203 | |||||||||||||||||||
| 204 | =cut | ||||||||||||||||||
| 205 | |||||||||||||||||||
| 206 | 1 | 1; # End of Sys::Group::GIDhelper | |||||||||||||||||