App/Helper.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 72 CC 4 SCAR 23.0
CC
4
Cov
0%
::entangle
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 10.0
1 package Web::App::Helper;
2  
3 use Class::Easy;
4  
5 use IO::Easy::File;
6 use IO::Easy::Dir;
7  
8 use Project::Easy::Config;
9 use Project::Easy::Helper;
10  
11 sub ::entangle {
12
13 $Class::Easy::DEBUG = 'immediately';
14  
15 Project::Easy::Helper::_script_wrapper (
16 IO::Easy::Dir->current->append ('bin', 'fake')
17 );
18
19 my $pack = $::project;
20
21 my $apxs_libexec;
22 my $apxs;
23
24 foreach my $apxs_cmd ((
25 'ap2xs',
26 'apxs',
27 'apxs2',
28 '/usr/sbin/apxs', # Old Fedora verions
29 '/usr/sbin/apxs2' # Opensuse "alias" [sic]
30 )) {
31 my $apxs_test = `$apxs_cmd -q LIBEXECDIR 2>/dev/null`;
32
33 chomp $apxs_test;
34 next unless $apxs_test;
35
36 $apxs_libexec = $apxs_test;
37 $apxs = $apxs_cmd;
38
39 }
40
41 die "no apxs libexec directory"
42 unless $apxs_libexec;
43  
44 debug "found apxs libexecdir $apxs_libexec";
45
46 my $httpd_dir = `$apxs -q SBINDIR`;
47 chomp $httpd_dir;
48 my $httpd_name = `$apxs -q TARGET`;
49 chomp $httpd_name;
50
51 my $httpd_bin = IO::Easy->new ($httpd_dir)->append ($httpd_name);
52
53 my $vars = {
54 root => $pack->root,
55 distro => $pack->distro,
56 project => $pack->id,
57 user => scalar getpwuid ($<),
58 group => scalar getgrgid ($(),
59 port => 50000,
60 admin => 'author@example.com',
61
62 apxs_libexec => $apxs_libexec,
63
64 httpd_bin => $httpd_bin,
65 };
66  
67 my $files = &IO::Easy::File::__data__files;
68
69 my $root = $pack->root;
70
71 my $global_config_patch_json = delete $files->{global_config_patch_json};
72 my $local_config_patch_json = delete $files->{local_config_patch_json};
73
74 debug "storing config files";
75
76 foreach my $deploy_file_tmpl (keys %$files) {
77
78 # for files with expansion
79 my $deploy_file_name = Project::Easy::Config::string_from_template (
80 $deploy_file_tmpl,
81 $vars
82 );
83  
84 my $deploy_file = $root->append ($deploy_file_name)->as_file;
85
86 my $deploy_dir = $deploy_file->parent;
87 $deploy_dir->create;
88
89 my $deploy_tmpl = $files->{$deploy_file_tmpl};
90 my $deploy_contents = Project::Easy::Config::string_from_template (
91 $deploy_tmpl,
92 $vars
93 );
94
95 my $result = $deploy_file->store_if_empty ($deploy_contents);
96
97 # TODO: make correct routine for file names comparison (etc/ and etc, as example)
98 # because some files may be incorrectly chmod'ed
99 if ($deploy_dir->name eq $pack->bin) { # and $deploy_dir->updir eq $pack->root) {
100 chmod (0755, $deploy_file);
101 }
102
103 # warn "something"
104 # unless defined $result;
105 }
106
107 debug "patching configuration for daemon";
108
109 # within helper we have json structures
110 my $serializer = Project::Easy::Config->serializer ('json');
111
112 # global config
113 my $patch = $serializer->parse_string ($global_config_patch_json);
114 $pack->conf_path->patch ($patch);
115  
116 # local config, variables expansion
117 $local_config_patch_json = Project::Easy::Config::string_from_template (
118 $local_config_patch_json,
119 $vars
120 );
121 $patch = $serializer->parse_string ($local_config_patch_json);
122 $pack->fixup_path->patch ($patch);
123
124 $pack->root->dir_io ('htdocs')->create;
125
126 debug "done";
127 }
128  
129 1;
130  
131 __DATA__