MLite/Helper/Install.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 97 CC 9 SCAR 38.3
CC
9
Cov
0%
install
90.0
BEGIN
2.0
BEGIN
2.0
CRAP 46.0
1 package WWW::MLite::Helper::Install;
2 use strict; # $Id: Install.pm 22 2014-07-24 14:09:51Z minus $
3 use Encode;
4
5 =pod
6
7 On future: encoding utf-8
8
9 =encoding windows-1251
10
11 =head1 NAME
12
13 WWW::MLite::Helper::Install - Helper of install Your project
14
15 =head1 VERSION
16
17 Version 1.00
18
19 =head1 SYNOPSIS
20
21 use WWW::MLite::Helper::Install;
22
23 WWW::MLite::Helper::Install::install(
24 DIRPROJECT => getcwd(),
25 ) or exit;
26
27 =head1 DESCRIPTION
28
29 Helper of install Your project. Please use it ONLY in Makefile.PL
30
31 =head2 METHODS
32
33 =over 8
34
35 =item B<install>
36
37 WWW::MLite::Helper::Install::install(
38 FOO => 'foo',
39 BAR => 'bar',
40 BAZ => 'baz',
41 # ...
42 );
43
44 Install Your project
45
46 =back
47
48 =head1 AUTHOR
49
50 Serz Minus (Lepenkov Sergey) L<http://www.serzik.com> E<lt>minus@mail333.comE<gt>
51
52 =head1 COPYRIGHT
53
54 Copyright (C) 1998-2014 D&D Corporation. All Rights Reserved
55
56 =head1 LICENSE
57
58 This program is free software: you can redistribute it and/or modify
59 it under the terms of the GNU General Public License as published by
60 the Free Software Foundation, either version 3 of the License, or
61 (at your option) any later version.
62
63 This program is distributed in the hope that it will be useful,
64 but WITHOUT ANY WARRANTY; without even the implied warranty of
65 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66 GNU General Public License for more details.
67
68 See C<LICENSE> file
69
70 =cut
71
72 use vars qw($VERSION);
73 $VERSION = '1.00';
74
75 use constant {
76 SKELDIR => "share/skel",
77 NOTSKEL => "Skeleton is not builded! Please check your project content",
78 TESTFILE => "index.cgi",
79 PERM_RWX => 0755,
80 PERM_DIR => 0777,
81 };
82
83 use CTK;
84 use TemplateM;
85 use Try::Tiny;
86 use File::Find;
87 use Cwd;
88 my $basedir = getcwd();
89
90 sub install {
91 my %h = @_;
92 my $c = new CTK;
93 my $srcdir = CTK::catdir(".",SKELDIR);
94
95 # Ïðîâåðêà íà óæå óñòàíîâëåííóþ ñèñòåìó
96 my $testfile = TESTFILE;
97 if ((-e $testfile) && $c->cli_prompt("Project already installed. Do You want to reinstall it?:",'no') !~ /^\s*y/i) {
98 say("Bye.");
99 return 0;
100 }
101
102 # Íà÷àëà óñòàíîâêè
103 say("Project installing...");
104 chdir($srcdir);
105 find({ wanted => sub {
106 if (-f $_) {
107 my $dst = CTK::catfile($basedir, $File::Find::dir, $_);
108 say "\tProcessing file $_ --> $dst";
109 try {
110 my $tpl = new TemplateM(-file => $_, -asfile => 1);
111 $tpl->stash({%h});
112 $tpl->cast_if('WIN32', $c->isostype("Windows"));
113 CTK::bsave($dst, $tpl->output(), 0)
114 if ((!-e $dst) || $c->cli_prompt("File \"$dst\" already exists. Overwrite it?:",'no') =~ /^\s*y/i);
115 if ($_ =~ /(\.cgi)|(\.pl)|(\.sh)$/) {
116 chmod PERM_RWX, $dst;
117 } elsif ($File::Find::dir =~ /[^a-z0-1]bin$/i) {
118 chmod PERM_RWX, $dst;
119 }
120 } catch {
121 say("\tERROR: $_");
122 };
123 } elsif (-d $_) {
124 if ($_ !~ /^\.+$/) {
125 my $dst = CTK::catdir($basedir, $File::Find::dir, $_);
126 if (!-e $dst) {
127 say "\tCreating directory $dst";
128 mkdir $dst;
129 chmod PERM_DIR, $dst;
130 }
131 }
132 } else {
133 say "\tSkipped $_. This is not file and not directory"
134 }
135
136 },
137 }, ".");
138 chdir($basedir);
139
140 }
141
142 1;
143