Web-App

 view release on metacpan or  search on metacpan

lib/Web/App/Helper.pm  view on Meta::CPAN

package Web::App::Helper;

use Class::Easy;

use IO::Easy::File;
use IO::Easy::Dir;

use Project::Easy::Config;
use Project::Easy::Helper;

sub ::entangle {
	
	$Class::Easy::DEBUG = 'immediately';

	Project::Easy::Helper::_script_wrapper (
		IO::Easy::Dir->current->append ('bin', 'fake')
	);
	
	my $pack = $::project;
	
	my $apxs_libexec;
	my $apxs;
	
	foreach my $apxs_cmd ((
		'ap2xs',
		'apxs',
		'apxs2',
		'/usr/sbin/apxs', # Old Fedora verions
		'/usr/sbin/apxs2' # Opensuse "alias" [sic]
	)) {
		my $apxs_test = `$apxs_cmd -q LIBEXECDIR 2>/dev/null`;
		
		chomp $apxs_test;
		next unless $apxs_test;
		
		$apxs_libexec = $apxs_test;
		$apxs = $apxs_cmd;
		
	}
	
	die "no apxs libexec directory"
		unless $apxs_libexec;

	debug "found apxs libexecdir $apxs_libexec";
	
	my $httpd_dir  = `$apxs -q SBINDIR`;
	chomp $httpd_dir;
	my $httpd_name = `$apxs -q TARGET`;
	chomp $httpd_name;
	
	my $httpd_bin = IO::Easy->new ($httpd_dir)->append ($httpd_name);
	
	my $vars = {
		root	=> $pack->root,
		distro  => $pack->distro,
		project => $pack->id,
		user	=> scalar getpwuid ($<),
		group   => scalar getgrgid ($(),
		port	=> 50000,
		admin   => 'author@example.com',
		
		apxs_libexec => $apxs_libexec,
		
		httpd_bin => $httpd_bin,
	};

	my $files = &IO::Easy::File::__data__files;
	
	my $root = $pack->root;
	
	my $global_config_patch_json = delete $files->{global_config_patch_json};
	my $local_config_patch_json  = delete $files->{local_config_patch_json};
	
	debug "storing config files";
	
	foreach my $deploy_file_tmpl (keys %$files) {
		
		# for files with expansion
		my $deploy_file_name = Project::Easy::Config::string_from_template (
			$deploy_file_tmpl,
			$vars
		);

		my $deploy_file = $root->append ($deploy_file_name)->as_file;
		
		my $deploy_dir = $deploy_file->parent;
		$deploy_dir->create;
		
		my $deploy_tmpl = $files->{$deploy_file_tmpl};
		my $deploy_contents = Project::Easy::Config::string_from_template (
			$deploy_tmpl,
			$vars
		);
		
		my $result = $deploy_file->store_if_empty ($deploy_contents);
		
		# TODO: make correct routine for file names comparison (etc/ and etc, as example)
		# because some files may be incorrectly chmod'ed
		if ($deploy_dir->name eq $pack->bin) { # and $deploy_dir->updir eq $pack->root) {
			chmod (0755, $deploy_file);
		}
		
		# warn "something"
		#	unless defined $result;
	}
	
	debug "patching configuration for daemon";
	
	# within helper we have json structures
	my $serializer = Project::Easy::Config->serializer ('json');
	
	# global config
	my $patch = $serializer->parse_string ($global_config_patch_json);
	$pack->conf_path->patch ($patch);

	# local config, variables expansion
	$local_config_patch_json = Project::Easy::Config::string_from_template (



( run in 2.094 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )