Skip to content

Commit

Permalink
first draft of perlbrew_lib LWRP
Browse files Browse the repository at this point in the history
  • Loading branch information
xdg committed Jan 7, 2012
1 parent 339f312 commit a1f9da6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
51 changes: 51 additions & 0 deletions 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

23 changes: 23 additions & 0 deletions 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.