Skip to content

Commit a5865bc

Browse files
author
Krzysztof Krzyżaniak (eloy)
committed
add versioning modules + uninstall option
1 parent 4ee7e48 commit a5865bc

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

lib/puppet/provider/package/cpanm.rb

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@
44

55
desc 'Install CPAN modules via `cpanm`'
66

7-
has_feature :installable, :upgradeable
8-
9-
commands :cpanm => "cpanm"
7+
has_feature :versionable
8+
has_feature :install_options
9+
has_feature :uninstall_options
10+
11+
confine :exists => ['/usr/bin/cpanm', '/usr/bin/perldoc']
12+
commands :cpanm => 'cpanm'
13+
14+
if command('cpanm')
15+
confine :true => begin
16+
cpanm('--version')
17+
rescue Puppet::ExecutionFailure
18+
false
19+
else
20+
true
21+
end
22+
end
1023

1124
# puppet requires an instances method that returns all packages
1225
# curently installed with this provider.
@@ -25,17 +38,17 @@ def self.instances
2538
# using a custom script that outputs the relevant info in a
2639
# similar format. Someone with more ruby knowledge probably could
2740
# make this better
28-
29-
list = `perl -MExtUtils::Installed -e '$installed = ExtUtils::Installed->new();printf qq{"Module" %s\n"VERSION: %s"\n},$_,$installed->version($_) for $installed->modules'`
30-
list.split(/\n/).collect do |line|
31-
case line
32-
when module_name_re
33-
pkg_info = { :name => $1, :provider => name }
34-
when module_vers_re
35-
pkg_info[:ensure] = $1
36-
packages << new(pkg_info)
37-
else
38-
next
41+
execpipe %q[perl -MExtUtils::Installed -e '$installed = ExtUtils::Installed->new(skip_cwd=>1);printf qq{"Module" %s\n"VERSION: %s"\n},$_,$installed->version($_) for $installed->modules'] do |process|
42+
process.collect do |line|
43+
case line
44+
when module_name_re
45+
pkg_info = { :name => $1, :provider => name }
46+
when module_vers_re
47+
pkg_info[:ensure] = $1
48+
packages << new(pkg_info)
49+
else
50+
next
51+
end
3952
end
4053
end
4154
debug packages.inspect
@@ -52,18 +65,23 @@ def query
5265

5366
# Install the module
5467
def install
55-
cpanm @resource[:name]
68+
if resource[:ensure].is_a? Symbol
69+
package = resource[:name]
70+
else
71+
package = "#{resource[:name]}@#{resource[:ensure]}"
72+
end
73+
cpanm(['--quiet', '--notest', package])
5674
end
5775

58-
# update the module
76+
# update the module
5977
def update
6078
cpanm @resource[:name]
6179
end
6280

63-
# uninstall the module
64-
# def uninstall
65-
# check out App::pmuninstall for a possible way to uninstall
66-
# end
81+
# Uninstall the module
82+
def uninstall
83+
cpanm(['--quiet', '--uninstall', @resource[:name]])
84+
end
6785

6886
# Return the latest available version of a particular module
6987
def latest

0 commit comments

Comments
 (0)