| 1 |
# PERL CPAN support |
|---|
| 2 |
Puppet::Type.type(:package).provide :cpan, :parent => Puppet::Provider::Package do |
|---|
| 3 |
desc "PERL CPAN support." |
|---|
| 4 |
|
|---|
| 5 |
has_feature :versionable |
|---|
| 6 |
|
|---|
| 7 |
commands :cpancmd => "perl" |
|---|
| 8 |
confine :exists => "/etc/perl/CPAN/Config.pm" # may be Debian specific |
|---|
| 9 |
|
|---|
| 10 |
def install(useversion = true) |
|---|
| 11 |
name = @resource[:name] |
|---|
| 12 |
if (! @resource.should(:ensure).is_a? Symbol) and useversion |
|---|
| 13 |
# we have to figure out the CPAN file name to install |
|---|
| 14 |
response = self.class.info(name) |
|---|
| 15 |
name = response['CPAN_FILE'].sub(/\d+\.\d+/, @resource.should(:ensure)) |
|---|
| 16 |
end |
|---|
| 17 |
|
|---|
| 18 |
cmd = self.class.shell_cmd('install', name) |
|---|
| 19 |
begin |
|---|
| 20 |
execute(cmd); |
|---|
| 21 |
rescue Puppet::ExecutionFailure => detail |
|---|
| 22 |
raise Puppet::Error, "Could not install CPAN module: %s" % name |
|---|
| 23 |
end |
|---|
| 24 |
end |
|---|
| 25 |
|
|---|
| 26 |
def latest |
|---|
| 27 |
response = self.class.info(@resource[:name]) |
|---|
| 28 |
if response['CPAN_VERSION'] |
|---|
| 29 |
return {:name => @resource[:name], :ensure => response['CPAN_VERSION'], :provider => :cpan} |
|---|
| 30 |
else |
|---|
| 31 |
raise Puppet::Error, "CPAN module #{@resource[:name]} not found" |
|---|
| 32 |
end |
|---|
| 33 |
end |
|---|
| 34 |
|
|---|
| 35 |
def query |
|---|
| 36 |
response = self.class.info(@resource[:name]) |
|---|
| 37 |
|
|---|
| 38 |
return {:name => @resource[:name], :ensure => response['INST_VERSION'], :provider => :cpan} |
|---|
| 39 |
end |
|---|
| 40 |
|
|---|
| 41 |
def self.info(name) |
|---|
| 42 |
cmd = shell_cmd('i', name) |
|---|
| 43 |
response = {} |
|---|
| 44 |
begin |
|---|
| 45 |
execute(cmd).split("\n").each do |line| |
|---|
| 46 |
response[$1] = $2 if /\s{4}(\S+)\s+(.*)/.match(line) |
|---|
| 47 |
end |
|---|
| 48 |
rescue Puppet::ExecutionFailure => detail |
|---|
| 49 |
raise Puppet::Error, "Could not list CPAN modules: %s" % detail |
|---|
| 50 |
end |
|---|
| 51 |
return response |
|---|
| 52 |
end |
|---|
| 53 |
|
|---|
| 54 |
def self.shell_cmd(cmd, mod) |
|---|
| 55 |
[command(:cpancmd), '-MCPAN', '-e', "CPAN::Shell->#{cmd}(\"#{mod}\")"] |
|---|
| 56 |
end |
|---|
| 57 |
|
|---|
| 58 |
def self.instances |
|---|
| 59 |
cmd = [command(:cpancmd), '-MCPAN', '-e', ' |
|---|
| 60 |
for $mod (CPAN::Shell->expand("Module","/./")){ |
|---|
| 61 |
$mod->inst_file ? printf("%s %s\n", $mod->id, $mod->inst_version||"none") : next; |
|---|
| 62 |
}'] |
|---|
| 63 |
|
|---|
| 64 |
begin |
|---|
| 65 |
list = execute(cmd).split("\n").collect do |line| |
|---|
| 66 |
new({:name => $1, :ensure => $2, :provider => :cpan}) if /(\S+) (\S+)/.match(line) |
|---|
| 67 |
end |
|---|
| 68 |
rescue Puppet::ExecutionFailure => detail |
|---|
| 69 |
raise Puppet::Error, "Could not list CPAN modules: %s" % detail |
|---|
| 70 |
end |
|---|
| 71 |
return list |
|---|
| 72 |
end |
|---|
| 73 |
|
|---|
| 74 |
def update |
|---|
| 75 |
self.install(false) |
|---|
| 76 |
end |
|---|
| 77 |
|
|---|
| 78 |
end |
|---|
| 79 |
|
|---|
| 80 |
# $Id$ |
|---|