# lib/puppet/provider/cpan/cpan.rb require'puppet/provider/package'Puppet::Type.type(:cpan).provide(:cpan,:parent=>Puppet::Provider::Package)dodesc"Installation of perl modules from cpan"commands:cpanm=>"/usr/bin/cpanm"ifPuppet::FileSystem.exist?'/usr/bin/cpanm'commands:perldoc=>"perldoc"# TODO add cpan as different way of installation.defcreatecpanmresource[:name]enddefdestroycpanm('-U','-f',resource[:name])enddefexists?beginperldoc('-l',resource[:name])truerescuePuppet::ExecutionFailure=>efalseendendend
# lib/puppet/type/cpan.rbPuppet::Type.newtype(:cpan)do@doc="Manage the installation and uninstallation of perl libraries from cpan repository using cpanminus manager, you can pass your own local cpan repository. Valid options :- 1. 'ensure' => present||absent # Present is the default options, absent will uninstall the perl libraries. 2. 'version' => latest # Latest version of perl libraries will get installed, if you want you can pass the version number. Example: cpan { 'Text::ASCIITable' : ensure => present } cpan { 'Text::ASCIITable' : ensure => present, version => '1.0.1'} "ensurabledodefaultvaluesdefaultto:presentendnewparam(:name,:namevar=>true)dodesc"Name of the Perl library"endnewproperty(:version)dodesc"Specify version number"validatedo|value|fail("Invalid version #{value}")unlessvalue=~/^[0-9A-Za-z\.:-]+$/endendend