4
4
5
5
desc 'Install CPAN modules via `cpanm`'
6
6
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
10
23
11
24
# puppet requires an instances method that returns all packages
12
25
# curently installed with this provider.
@@ -25,17 +38,17 @@ def self.instances
25
38
# using a custom script that outputs the relevant info in a
26
39
# similar format. Someone with more ruby knowledge probably could
27
40
# 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
39
52
end
40
53
end
41
54
debug packages . inspect
@@ -52,18 +65,23 @@ def query
52
65
53
66
# Install the module
54
67
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 ] )
56
74
end
57
75
58
- # update the module
76
+ # update the module
59
77
def update
60
78
cpanm @resource [ :name ]
61
79
end
62
80
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
67
85
68
86
# Return the latest available version of a particular module
69
87
def latest
0 commit comments