Skip to content
Browse files

first draft of perlbrew_lib LWRP

  • Loading branch information...
1 parent 339f312 commit a1f9da64281e71126545deaded004a1f316549cc @xdg xdg committed Jan 6, 2012
Showing with 74 additions and 0 deletions.
  1. +51 −0 cookbooks/perlbrew/providers/lib.rb
  2. +23 −0 cookbooks/perlbrew/resources/lib.rb
View
51 cookbooks/perlbrew/providers/lib.rb
@@ -0,0 +1,51 @@
+#
+# Author:: David A. Golden
+# Cookbook Name:: perlbrew
+# Provider:: perlbrew_perl
+#
+# Copyright:: 2012, David A. Golden <dagolden@cpan.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'chef/mixin/shell_out'
+require 'chef/mixin/language'
+include Chef::Mixin::ShellOut
+
+action :create do
+ unless @perl.created
+ execute "Create perlbrew lib #{new_resource.name}" do
+ environment ({'PERLBREW_ROOT' => node['perlbrew']['perlbrew_root']})
+ environment ({'PERLBREW_HOME' => node['perlbrew']['perlbrew_root']})
+ command "#{node['perlbrew']['perlbrew_root']}/bin/perlbrew lib create #{new_resource.name}"
+ end
+ new_resource.updated_by_last_action(true)
+ end
+end
+
+action :delete do
+ if @perl.installed
+ execute "Remove perlbrew #{new_resource.name}" do
+ environment ({'PERLBREW_ROOT' => node['perlbrew']['perlbrew_root']})
+ environment ({'PERLBREW_HOME' => node['perlbrew']['perlbrew_root']})
+ command "#{node['perlbrew']['perlbrew_root']}/bin/perlbrew lib delete #{new_resource.name}"
+ end
+ new_resource.updated_by_last_action(true)
+ end
+end
+
+def load_current_resource
+ @lib = Chef::Resource::PerlbrewLib.new(new_resource.name)
+ @perl.created(::File.exists?("#{node['perlbrew']['perlbrew_root']}/perls/#{@perl.name}"))
+end
+
View
23 cookbooks/perlbrew/resources/lib.rb
@@ -0,0 +1,23 @@
+#
+# Author:: David A. Golden
+# Cookbook Name:: perlbrew
+# Resource:: perlbrew_perl
+#
+# Copyright:: 2012, David A. Golden <dagolden@cpan.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+actions :create, :delete
+
+attribute :created, :default => false

0 comments on commit a1f9da6

Please sign in to comment.
Something went wrong with that request. Please try again.