SBoKeeper/Database.pm

filter: Statementstmt 95.1% 253 / 266 Branchbran 73.7% 59 / 80 Conditioncond 57.1% 8 / 14 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 33 / 33 Podpod 92.0% 23 / 25 totaltotal 88.7% 378 / 426 CC 61 SCAR 16.1
CC
61
Cov
89%
read_data
11.3
add
8.1
tack
7.3
CRAP 5.0
« SBoKeeper/Config.pm ↑ Summary SBoKeeper/System.pm »
1 package Slackware::SBoKeeper::Database;
2 3 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 our $VERSION = '2.06';
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use List::Util qw(any uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 16 ▶sub write_data {
Subroutine write_data: called CC=6 SCAR=18.1
Pod undocumented
10  
11 16 my $data = shift;
12 16 my $out = shift;
13  
14 16 my $outstr = '';
15  
16 16 ▶ open my $fh, '>', $out // \$outstr
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $out // \$outstr or die sprintf("Failed to open %s for writing: $!\n", $out // "in-memory scalar") 16 0 16
Condition50%2/4
$out // \$outstr
l!l
151
$out // "in-memory scalar"
l!l
00
MC/DC100%1/1
$out // \$outstr
$out
MC/DC0%0/1
$out // "in-memory scalar"
$out
Truth table100%2/2
A
A= $out
Aresult
11
00
Truth table0%0/2
A
A= $out
Aresult
11
00
17 or die sprintf "Failed to open %s for writing: $!\n", $out // 'in-memory scalar';
18  
19 16 foreach my $p (sort keys %{$data}) {
20  
21 109 say { $fh } "PACKAGE: $p";
22 109 say { $fh } "DEPS: ", join(' ', @{$data->{$p}->{Deps}});
23 109 say { $fh } "MANUAL: $data->{$p}->{Manual}";
24 109 say { $fh } '%%';
25  
26 }
27  
28 16 close $fh;
29  
30 16 ▶ return $out // $outstr;
Condition66%2/3
$out // $outstr
l!l&&r!l&&!r
1510
MC/DC0%0/2
$out // $outstr
$out $outstr
Truth table33%1/3
A // B
A= $outB= $outstr
ABresult
1X1
011
000
31  
32 }
33  
34 31 ▶sub read_data {
Subroutine read_data: called CC=11 SCAR=24.3
Pod undocumented
35  
36 31 my $file = shift;
37 31 ▶ my $blacklist = shift // {};
Condition50%1/2
shift() // {}
l!l
310
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
38  
39 31 my $data = {};
40  
41 31 ▶ open my $fh, '<', $file or die "Failed to open $file for reading: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Failed to open $file for reading: $!\n" 31 0 31
42  
43 31 my $pkg = '';
44 31 my $lnum = 1;
45  
46 31 ▶ while (my $l = readline $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline $fh)) 1372 31 1403
47  
48 1372 chomp $l;
49  
50 1372 ▶ if ($l eq '%%') {
Branch: 5 branches
BranchTrueFalseTotal
if ($l eq '%%') { } 343 1029 1372
elsif ($l =~ /^PACKAGE: /u) { } 343 686 1029
elsif ($pkg eq '') { } 0 686 686
elsif ($l =~ /^DEPS: /u) { } 343 343 686
elsif ($l =~ /^MANUAL: /u) { } 343 0 343
51 343 $pkg = '';
52 } elsif ($l =~ /^PACKAGE: /) {
53 343 $pkg = $l =~ s/^PACKAGE: //r;
54 343 $data->{$pkg} = {};
55 } elsif ($pkg eq '') {
56 0 die "Bad line in $file at line $lnum: PACKAGE not set\n";
57 } elsif ($l =~ /^DEPS: /) {
58 343 my $depstr = $l =~ s/^DEPS: //r;
59 343 @{$data->{$pkg}->{Deps}} =
60 343 grep { not exists $blacklist->{$_} }
61 split /\s/, $depstr;
62 } elsif ($l =~ /^MANUAL: /) {
63 343 my $manual = $l =~ s/^MANUAL: //r;
64 343 ▶ $data->{$pkg}->{Manual} = $manual eq '1' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$manual eq '1' ? : 45 298 343
65 } else {
66 0 die "Bad line in $file at line $lnum\n";
67 }
68  
69 1372 $lnum++;
70  
71 }
72  
73 31 close $fh;
74  
75 # Weed out blacklisted packages
76 31 for my $p (keys %{$blacklist}) {
77 31 delete $data->{$p};
78 }
79  
80 31 return $data;
81  
82 }
83  
84 41 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
85  
86 41 my $class = shift;
87 41 my $file = shift;
88 41 my $sbodir = shift;
89 41 ▶ my $blacklist = shift // {};
Condition100%2/2
shift() // {}
l!l
392
MC/DC100%1/1
shift() // {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
90  
91 41 $blacklist->{'%README%'} = 1;
92  
93 41 my $self = {
94 _data => {},
95 _sbodir => '',
96 _blacklist => $blacklist,
97 };
98  
99 41 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 31 10 41
100 31 $self->{_data} = read_data($file, $self->{_blacklist});
101 }
102  
103 41 $self->{_sbodir} = $sbodir;
104  
105 41 bless $self, $class;
106 41 return $self;
107  
108 }
109  
110 76 ▶sub add {
Subroutine add: called CC=8 SCAR=20.9
Pod documented
111  
112 76 my $self = shift;
113 76 my $pkgs = shift;
114 76 my $manual = shift;
115  
116 76 my %added;
117 76 my $n = 0;
118  
119 76 foreach my $p (@{$pkgs}) {
120  
121 86 ▶ next if $self->blacklist($p);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blacklist($p) 0 86 86
122  
123 86 ▶ unless ($self->exists($p)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->exists($p)) 0 86 86
124 0 die "$p does not exist in SlackBuild repo\n";
125 }
126  
127 # pkg already present, do not add. Set manual flag if desired.
128 86 ▶ if (defined $self->{_data}->{$p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_data"}{$p}) 19 67 86
129 19 ▶ $self->{_data}->{$p}->{Manual} = $manual if $manual;
Branch: 1 branch
BranchTrueFalseTotal
if $manual 1 18 19
130 19 next;
131 }
132  
133 67 $self->{_data}->{$p}->{Manual} = $manual;
134  
135 67 my @deps = $self->real_immediate_dependencies($p);
136 67 $self->{_data}->{$p}->{Deps} = \@deps;
137  
138 67 my @add = $self->add($self->{_data}->{$p}->{Deps}, 0);
139  
140 67 for my $ad (@add) {
141 124 ▶ $added{$ad} = $n++ unless exists $added{$ad};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $added{$ad} 124 0 124
142 }
143  
144 67 $added{$p} = $n++;
145  
146 }
147  
148 76 return sort { $added{$a} <=> $added{$b} } keys %added;
149  
150 }
151  
152 6 ▶sub tack {
Subroutine tack: called CC=6 SCAR=19.9
Pod documented
153  
154 6 my $self = shift;
155 6 my $pkgs = shift;
156 6 my $manual = shift;
157  
158 6 my @tack;
159  
160 6 foreach my $p (@{$pkgs}) {
161  
162 15 ▶ next if $self->blacklist($p);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blacklist($p) 0 15 15
163  
164 15 ▶ unless ($self->exists($p)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->exists($p)) 0 15 15
165 0 die "$p does not exist in SlackBuild repo\n";
166 }
167  
168 15 ▶ if (defined $self->{_data}->{$p} and $manual) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_data'}{$p} and $manual) { } 0 15 15
Condition33%1/3
defined $self->{"_data"}{$p} and $manual
!ll&&!rl&&r
1500
MC/DC0%0/2
defined $self->{"_data"}{$p} and $manual
defined $self->{"_data"}{$p} $manual
Truth table33%1/3
A and B
A= defined $self->{"_data"}{$p}B= $manual
ABresult
0X0
100
111
169 0 $self->{_data}->{$p}->{Manual} = $manual;
170 0 push @tack, $p;
171 } else {
172 15 $self->{_data}->{$p} = {
173 Deps => [],
174 Manual => $manual,
175 };
176 15 push @tack, $p;
177 }
178  
179 }
180  
181 6 return @tack;
182  
183 }
184  
185 7 ▶sub remove {
Subroutine remove: called CC=3 SCAR=11.3
Pod documented
186  
187 7 my $self = shift;
188 7 my $pkgs = shift;
189  
190 7 my @rm;
191  
192 7 foreach my $p (@{$pkgs}) {
193  
194 30 ▶ unless (defined $self->{_data}->{$p}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_data"}{$p}) 0 30 30
195 0 warn "$p not present in database, not removing\n";
196 0 next;
197 }
198  
199 30 delete $self->{_data}->{$p};
200  
201 30 push @rm, $p;
202  
203 }
204  
205 7 return sort @rm;
206  
207 }
208  
209 3 ▶sub depadd {
Subroutine depadd: called CC=6 SCAR=18.9
Pod documented
210  
211 3 my $self = shift;
212 3 my $pkg = shift;
213 3 my $deps = shift;
214  
215 3 ▶ unless ($self->has($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has($pkg)) 0 3 3
216 0 die "$pkg is not present in database\n";
217 }
218  
219 3 my @add;
220 3 foreach my $d (@{$deps}) {
221  
222 6 ▶ next if $self->blacklist($d);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blacklist($d) 0 6 6
223  
224 6 ▶ unless ($self->has($d)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has($d)) 0 6 6
225 0 warn "$d not present in database, skipping\n";
226 0 next;
227 }
228  
229 6 ▶ unless (any { $d eq $_ } @{$self->{_data}->{$pkg}->{Deps}}) {
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
unless (&any(sub { $d eq $_; } , @{$$self{"_data"}{$pkg}{"Deps"};})) 6 0 6
230 6 push @{$self->{_data}->{$pkg}->{Deps}}, $d;
231 6 push @add, $d;
232 }
233  
234 }
235  
236 3 return @add;
237  
238 }
239  
240 2 ▶sub depremove {
Subroutine depremove: called CC=3 SCAR=11.0
Pod documented
241  
242 2 my $self = shift;
243 2 my $pkg = shift;
244 2 my $deps = shift;
245  
246 2 my @kept;
247 my @rm;
248 2 foreach my $p (@{$self->{_data}->{$pkg}->{Deps}}) {
249 6 ▶ if (any { $p eq $_ } @{$deps}) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $p eq $_; } , @{$deps;})) { } 4 2 6
250 4 push @rm, $p;
251 } else {
252 2 push @kept, $p;
253 }
254 }
255  
256 2 $self->{_data}->{$pkg}->{Deps} = \@kept;
257  
258 2 return @rm;
259  
260 }
261  
262 126 ▶sub has {
Subroutine has: called CC=1 SCAR=0.0
Pod documented
263  
264 126 my $self = shift;
265 126 my $pkg = shift;
266  
267 126 return defined $self->{_data}->{$pkg};
268  
269 }
270  
271 116 ▶sub packages {
Subroutine packages: called CC=1 SCAR=0.0
Pod documented
272  
273 116 my $self = shift;
274  
275 116 return sort keys %{$self->{_data}};
276  
277 }
278  
279 5 ▶sub missing {
Subroutine missing: called CC=3 SCAR=11.0
Pod documented
280  
281 5 my $self = shift;
282  
283 5 my %missing;
284  
285 5 foreach my $p ($self->packages) {
286  
287 my @pmissing =
288 49 grep { !$self->has($_) }
289 $self->real_immediate_dependencies($p);
290  
291 49 ▶ push @{$missing{$p}}, @pmissing if @pmissing;
Branch: 1 branch
BranchTrueFalseTotal
if @pmissing 5 44 49
292  
293 }
294  
295 5 return %missing;
296  
297 }
298  
299 2 ▶sub extradeps {
Subroutine extradeps: called CC=3 SCAR=11.0
Pod documented
300  
301 2 my $self = shift;
302  
303 2 my @pkgs = $self->packages;
304  
305 2 my %extra;
306  
307 2 foreach my $p (@pkgs) {
308  
309 15 my %realdeps = map { $_ => 1 } $self->real_immediate_dependencies($p);
310  
311 my @pextra =
312 15 grep { !defined $realdeps{$_} }
313 $self->immediate_dependencies($p);
314  
315 15 ▶ push @{$extra{$p}}, @pextra if @pextra;
Branch: 1 branch
BranchTrueFalseTotal
if @pextra 2 13 15
316  
317 }
318  
319 2 return %extra;
320  
321 }
322  
323 82 ▶sub is_necessary {
Subroutine is_necessary: called CC=3 SCAR=11.1
Pod documented
324  
325 82 my $self = shift;
326 82 my $pkg = shift;
327  
328 82 ▶ unless (defined $self->{_data}->{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_data"}{$pkg}) 0 82 82
329 0 return 0;
330 }
331  
332 82 ▶ if ($self->{_data}->{$pkg}->{Manual}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_data"}{$pkg}{"Manual"}) 6 76 82
333 6 return 1;
334 }
335  
336 # Check if $pkg is a dependency of any manually installed package
337  
338 return
339 66 ▶ any { $self->is_dependency($pkg, $_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
340 76 grep { $self->is_manual($_) }
341 $self->packages
342 ;
343  
344 }
345  
346 86 ▶sub is_dependency {
Subroutine is_dependency: called CC=4 SCAR=13.9
Pod documented
347  
348 86 my $self = shift;
349 86 my $dep = shift;
350 86 my $of = shift;
351  
352 86 foreach my $p (@{$self->{_data}->{$of}->{Deps}}) {
353  
354 20 ▶ if ($p eq $dep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p eq $dep) 5 15 20
355 5 return 1;
356 }
357  
358 15 ▶ if ($self->is_dependency($dep, $p)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_dependency($dep, $p)) 2 13 15
359 2 return 1;
360 }
361  
362 }
363  
364 79 return 0;
365  
366 }
367  
368 85 ▶sub is_immediate_dependency {
Subroutine is_immediate_dependency: called CC=3 SCAR=11.0
Pod documented
369  
370 85 my $self = shift;
371 85 my $dep = shift;
372 85 my $of = shift;
373  
374 85 foreach my $p (@{$self->{_data}->{$of}->{Deps}}) {
375 90 ▶ if ($p eq $dep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p eq $dep) 8 82 90
376 8 return 1;
377 }
378 }
379  
380 77 return 0;
381  
382 }
383  
384 975 ▶sub is_manual {
Subroutine is_manual: called CC=2 SCAR=6.9
Pod documented
385  
386 975 my $self = shift;
387 975 my $pkg = shift;
388  
389 975 ▶ return $self->{_data}->{$pkg}->{Manual} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_data'}{$pkg}{'Manual'} ? : 82 893 975
390  
391 }
392  
393 108 ▶sub exists {
Subroutine exists: called CC=3 SCAR=11.0
Pod documented
394  
395 108 my $self = shift;
396 108 my $pkg = shift;
397  
398 108 ▶ return 0 if $self->blacklist($pkg);
Branch: 1 branch
BranchTrueFalseTotal
if $self->blacklist($pkg) 0 108 108
399  
400 3 ▶ if (() = glob "$self->{_sbodir}/*/$pkg/$pkg.info") {
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (() = glob("$self->{'_sbodir'}/*/$pkg/$pkg.info")) { } 107 1 108
401 107 return 1;
402 } else {
403 1 return 0;
404 }
405  
406 }
407  
408 387 ▶sub blacklist {
Subroutine blacklist: called CC=1 SCAR=0.0
Pod documented
409  
410 387 my $self = shift;
411 387 my $pkg = shift;
412  
413 387 return exists $self->{_blacklist}->{$pkg};
414  
415 }
416  
417 12 ▶sub dependencies {
Subroutine dependencies: called CC=2 SCAR=6.9
Pod documented
418  
419 12 my $self = shift;
420 12 my $pkg = shift;
421  
422 12 my @deps;
423  
424 12 @deps = $self->immediate_dependencies($pkg);
425  
426 12 foreach my $d (@deps) {
427 11 push @deps, $self->dependencies($d);
428 }
429  
430 12 return uniq sort @deps;
431  
432 }
433  
434 60 ▶sub immediate_dependencies {
Subroutine immediate_dependencies: called CC=1 SCAR=0.0
Pod documented
435  
436 60 my $self = shift;
437 60 my $pkg = shift;
438  
439 60 return sort @{$self->{_data}->{$pkg}->{Deps}};
440  
441 }
442  
443 12 ▶sub real_dependencies {
Subroutine real_dependencies: called CC=2 SCAR=6.9
Pod documented
444  
445 12 my $self = shift;
446 12 my $pkg = shift;
447  
448 12 my @deps;
449  
450 12 @deps = $self->real_immediate_dependencies($pkg);
451  
452 12 foreach my $d (@deps) {
453 11 push @deps, $self->real_dependencies($d);
454 }
455  
456 12 return uniq sort @deps;
457  
458 }
459  
460 144 ▶sub real_immediate_dependencies {
Subroutine real_immediate_dependencies: called CC=6 SCAR=18.0
Pod documented
461  
462 144 my $self = shift;
463 144 my $pkg = shift;
464  
465 144 my @deps;
466  
467 144 my ($info) = glob "$self->{_sbodir}/*/$pkg/$pkg.info";
468  
469 144 ▶ die "Could not find $pkg in $self->{_sbodir}\n" unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 144 144
470  
471 144 ▶ open my $fh, '<', $info
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $info or die "Failed to open $info for reading: $!\n" 144 0 144
472 or die "Failed to open $info for reading: $!\n";
473  
474 144 ▶ while (my $l = readline $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline $fh)) 921 0 921
475  
476 921 chomp $l;
477  
478 921 ▶ next unless $l =~ /^REQUIRES=".*("|\\)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /^REQUIRES=".*("|\\)$/u 777 144 921
479  
480 144 my ($depstr) = $l =~ /^REQUIRES="(.*)("|\\)/;
481  
482 144 @deps = grep { !$self->blacklist($_) } split /\s/, $depstr;
483  
484 144 ▶ while (substr($l, -1) eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($l, -1) eq "\\") 3 144 147
485  
486 3 $l = readline $fh;
487 3 chomp $l;
488  
489 3 ($depstr) = $l =~ /(^.*)("|\\)/;
490  
491 3 push @deps, grep { !$self->blacklist($_) } split(" ", $depstr);
492  
493 }
494  
495 144 last;
496  
497 }
498  
499 144 close $fh;
500  
501 144 return sort @deps;
502  
503 }
504  
505 7 ▶sub reverse_dependencies {
Subroutine reverse_dependencies: called CC=1 SCAR=0.0
Pod documented
506  
507 7 my $self = shift;
508 7 my $pkg = shift;
509  
510 return grep {
511 7 $self->is_immediate_dependency($pkg, $_)
512 } $self->packages;
513  
514 }
515  
516 5 ▶sub unmanual {
Subroutine unmanual: called CC=2 SCAR=7.2
Pod documented
517  
518 5 my $self = shift;
519 5 my $pkg = shift;
520  
521 5 ▶ unless (defined $self->{_data}->{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_data"}{$pkg}) 0 5 5
522 0 return 0;
523 }
524  
525 5 $self->{_data}->{$pkg}->{Manual} = 0;
526  
527 5 return 1;
528  
529 }
530  
531 16 ▶sub write {
Subroutine write: called CC=1 SCAR=0.0
Pod documented
532  
533 16 my $self = shift;
534 16 my $path = shift;
535  
536 16 write_data($self->{_data}, $path);
537  
538 }
539  
540 3 1;
541  
542  
543  
544 =head1 NAME
545  
546 Slackware::SBoKeeper::Database - Read/write sbokeeper databases
547  
548 =head1 SYNOPSIS
549  
550 use Slackware::SBoKeeper::Database;
551  
552 my $database = Slackware::SBoKeeper::Database->new($file, $repo);
553 ...
554  
555 =head1 DESCRIPTION
556  
557 Slackware::SBoKeeper::Database is a module that handles reading and writing
558 L<sbokeeper> package database files. It is not meant to be used outside of
559 L<sbokeeper>. For user documentation of L<sbokeeper>, please consult its manual.
560  
561 =head1 SUBROUTINES/METHODS
562  
563 =head2 new($path, $sbodir, [ $blacklist ])
564  
565 Returns blessed Slackware::SBoKeeper::Database object. $path is the path to a
566 file containing B<sbokeeper> data. If $path is '', creates an empty
567 database. $sbodir is the directory where the SBo repository is stored.
568  
569 $blacklist is a hash ref of packages to ignore. Defaults to empty hash ref if
570 no hash is supplied.
571  
572 =head2 add($pkgs, $manual)
573  
574 Add array ref of pkgs and their dependencies to object. If $manual is true,
575 $pkgs are set to manually added (dependencies are still not).
576  
577 Returns array of packages added.
578  
579 =head2 tack($pkgs, $manual)
580  
581 Add array ref of pkgs to database. $manual determines whether they are marked
582 as manually added or not. Does not pull in dependencies.
583  
584 Returns array of packages added.
585  
586 =head2 remove($pkgs)
587  
588 Remove array ref pkgs from object. Dependencies pulled in from removed packages
589 will still remain.
590  
591 Returns array of packages removed.
592  
593 =head2 depadd($pkg, $deps)
594  
595 Add array ref $deps to $pkg's dependencies. $deps must be a list of packages
596 already present in the database.
597  
598 Returns list of dependencies added to $pkg.
599  
600 =head2 depremove($pkg, $deps)
601  
602 Removes array ref $deps from $pkg's dependency list.
603  
604 Returns list of dependencies removed.
605  
606 =head2 has($pkg)
607  
608 Returns 1 or 0 depending on whether $pkg is currently in the database.
609  
610 =head2 packages()
611  
612 Returns array of packages present in database.
613  
614 =head2 missing()
615  
616 Returns hash of packages and their missing dependencies, according to the
617 SlackBuild repo.
618  
619 =head2 extradeps()
620  
621 Returns hash of packages with extra dependencies. An extra dependency is a
622 dependency that is not required by the package in the SlackBuild repo.
623  
624 =head2 is_necessary($pkg)
625  
626 Checks to see if $pkg is necessary (manually added or dependency on a manually
627 added package). Returns 1 for yes, 0 for no.
628  
629 =head2 is_dependency($dep, $of)
630  
631 Checks to see if $dep is a dependency (or a dependency of a dependency, etc.) of
632 $of. Returns 1 for yes, 0 for no.
633  
634 $dep and $of must already be added to the object.
635  
636 =head2 is_immediate_dependency($dep, $of)
637  
638 Checks to see if $dep is a dependency of $of. Returns 1 for yes, 0 for no.
639  
640 $dep and $of must already be added to the object.
641  
642 =head2 is_manual($pkg)
643  
644 Checks if $pkg is manually installed. Returns 1 for yes, 0 no.
645  
646 =head2 exists($pkg)
647  
648 Checks if $pkg is present in repo. Returns 1 for yes, 0 for no.
649  
650 =head2 blacklist($pkg)
651  
652 Checks if $pkg is in the blacklist. Returns 1 for yes, 0 for no.
653  
654 =head2 dependencies($pkg)
655  
656 Returns list of packages that are a dependency of $pkg, according to the
657 database.
658  
659 =head2 immediate_dependencies($pkg)
660  
661 Returns list of packages that are an immediate dependency of $pkg, according to
662 the database. Does not return dependencies of those dependencies.
663  
664 =head2 real_dependencies($pkg)
665  
666 Returns list of packages that are a dependency of $pkg, according to the
667 SlackBuild repo. $pkg does not have to have been added previously.
668  
669 =head2 real_immediate_dependencies($pkg)
670  
671 Returns list of packages that are an immediate dependency of $pkg, according
672 to the SlackBuild repo. Does not return packages that are dependencies of those
673 dependencies. $pkg does not have to have been added previously.
674  
675 =head2 reverse_dependencies($pkg)
676  
677 Returns list of packages that depend on $pkg, according to the sbokeeper
678 database.
679  
680 =head2 unmanual($pkg)
681  
682 Unset $pkg as manually installed. Returns 1 if successful, 0 if not.
683  
684 =head2 write([$path])
685  
686 Writes data file to C<$path>, or returns string of would-be written data if
687 C<$path> is omitted.
688  
689 =head1 DATA FILES
690  
691 B<sbokeeper> data files are text files. Data files contain packages, which are
692 a series of lines that contain package information ended by a pair of percentage
693 signs (%%). A package entry should look something like this:
694  
695 PACKAGE: libreoffice
696 DEPS: avahi zulu-openjdk8
697 MANUAL: 1
698 %%
699  
700 =over 4
701  
702 =item PACKAGE
703  
704 Name of the package, which must have a corresponding SlackBuild in the
705 configured SlackBuild repo. This must be the first line in a package entry.
706  
707 =item DEPS
708  
709 Whitespace-seperated list of packages that PACKAGE depends on. Each package
710 must be present in the SlackBuild repo.
711  
712 =item MANUAL
713  
714 Specifies whether the package was manually added or not. 1 for yes, 0 for no.
715  
716 =item %%
717  
718 Marks the end of the current package entry.
719  
720 =back
721  
722 =head1 AUTHOR
723  
724 Written by Samuel Young E<lt>samyoung12788@gmail.comE<gt>.
725  
726 =head1 BUGS
727  
728 This module does not know how to handle circular dependencies. This should not
729 be a problem if you stick with the official SlackBuild repo. One should
730 exercise caution when using the depadd method, as it can easily introduce
731 circular dependencies.
732  
733 Report bugs on my Codeberg, L<https://codeberg.org/1-1sam>.
734  
735 =head1 COPYRIGHT
736  
737 Copyright (C) 2024-2025 Samuel Young
738  
739 This program is free software; you can redistribute it and/or modify it under
740 the terms of either: the GNU General Public License as published by the Free
741 Software Foundation; or the Artistic License.
742  
743 =head1 SEE ALSO
744  
745 L<sbokeeper>
746  
747 =cut
« SBoKeeper/Config.pm ↑ Summary SBoKeeper/System.pm »