| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # | ||
| 4 | # Author: Slaven Rezic | ||
| 5 | # | ||
| 6 | # Copyright (C) 2017,2018,2022 Slaven Rezic. All rights reserved. | ||
| 7 | # This package is free software; you can redistribute it and/or | ||
| 8 | # modify it under the same terms as Perl itself. | ||
| 9 | # | ||
| 10 | # Mail: slaven@rezic.de | ||
| 11 | # WWW: http://www.rezic.de/eserte/ | ||
| 12 | # | ||
| 13 | |||
| 14 | package Doit::Brew; # Convention: all commands here should be prefixed with 'brew_' | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | use warnings; | ||
| 18 | our $VERSION = '0.012'; | ||
| 19 | |||
| 20 | sub new { bless {}, shift } | ||
| 21 | sub functions { qw(brew_install_packages brew_missing_packages can_brew) } | ||
| 22 | |||
| 23 | sub can_brew { | ||
| 24 | my($self) = @_; | ||
| 25 | $self->which('brew') ? 1 : 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub brew_install_packages { | ||
| 29 | my($self, @packages) = @_; | ||
| 30 | my @missing_packages = $self->brew_missing_packages(@packages); | ||
| 31 | if (@missing_packages) { | ||
| 32 | $self->system('brew', 'install', @missing_packages); | ||
| 33 | } | ||
| 34 | @missing_packages; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub brew_missing_packages { | ||
| 38 | my($self, @packages) = @_; | ||
| 39 | my @missing_packages; | ||
| 40 | for my $package (@packages) { | ||
| 41 | if (!-d "/usr/local/Cellar/$package") { | ||
| 42 | push @missing_packages, $package; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | @missing_packages; | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | __END__ |