File Coverage

blib/script/narada-new-1
Criterion Covered Total %
statement 49 50 98.0
branch 20 30 66.6
condition n/a
subroutine 9 9 100.0
pod n/a
total 78 89 87.6


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2 1     1   541 use 5.010001;
  1         2  
3 1     1   3 use warnings;
  1         1  
  1         31  
4 1     1   2 use strict;
  1         1  
  1         16  
5 1     1   504 use utf8;
  1         8  
  1         5  
6              
7             our $VERSION = 'v2.3.7';
8              
9 1     1   35 use FindBin;
  1         1  
  1         47  
10 1     1   420 use lib "$FindBin::Bin/../lib/perl5";
  1         491  
  1         5  
11 1     1   441 use MIME::Base64;
  1         553  
  1         455  
12              
13              
14             main(@ARGV) if !caller;
15              
16              
17 3     3   45 sub err { die "narada-new-1: @_\n" };
18              
19             sub main {
20 7 100   7   13153 die "Usage: narada-new-1 [/path/to/project]\n" if @_ > 1;
21 6 100       18 my $dst = @_ ? $_[0] : q{.};
22              
23             # Prepare empty destination directory.
24 6 100       43 if (!-e $dst) {
25 1 50       23 mkdir $dst or err "mkdir: $!";
26             }
27             else {
28 5 100       67 -d $dst or err "Not a directory: $dst";
29 4 50       67 opendir my $d, $dst or err "opendir: $!";
30 4 100       152 (my @tmp = readdir $d) == 2 or err "Directory not empty: $dst";
31 2 50       21 closedir $d or err "closedir: $!";
32             }
33              
34             # Unpack project skeleton from DATA.
35 3         51 local $/;
36 3         237 my $skel = ;
37 3         33 local $SIG{PIPE} = 'IGNORE';
38 3 50       19 my $TAR = (grep {-x "$_/gtar"} split /:/ms, $ENV{PATH}) ? 'gtar' : 'tar';
  30         220  
39 3 50       1757 open my $unpack, q{|-}, "$TAR xpf - -C \Q$dst\E"
40             or err 'Unpack failed';
41 3         2484 print {$unpack} decode_base64($skel);
  3         491  
42 3 50       16768 close $unpack or err 'Unpack failed';
43              
44             # Enter project.
45 3 50       43 chdir $dst or err "chdir: $!";
46              
47 3         699 require Narada::Config;
48 3         49 Narada::Config->import(qw( set_config ));
49              
50             # Setup project version.
51 3 50       7076 my ($project) = `pwd` =~ m{([^/]+?)\n\z}xms
52             or err 'Unable to detect project name';
53 3         21 my $version = "$project-0.0.000";
54 3         43 set_config('version', "$version\n");
55              
56 3 50       16 if (exists $ENV{NARADA_USER}) {
57 0         0 set_config("patch/send/$ENV{USER}", $ENV{NARADA_USER});
58             }
59              
60             # Initialize patch system.
61 3         26913 system $TAR.' cf - ./ --exclude var/patch/.prev | tar xpf - -C var/patch/.prev/';
62              
63             # Make initial archive for installing this project elsewhere.
64 3         2806040 system 'narada-backup';
65 3 50       257 rename 'var/backup/full.tar', "var/patch/$version.tar" or err "rename: $!";
66              
67 3         229 return;
68             }
69              
70              
71             1; # Magic true value required at end of module
72             ## no critic (RequirePodAtEnd)
73              
74             =encoding utf8
75              
76             =head1 NAME
77              
78             narada-new-1 - creates a skeleton project based on Narada framework v1.x
79              
80              
81             =head1 VERSION
82              
83             This document describes narada-new-1 version v2.3.7
84              
85              
86             =head1 USAGE
87              
88             narada-new-1 [/path/to/project]
89              
90              
91             =head1 DESCRIPTION
92              
93             B This script shouldn't be used for new projects, use narada-new
94             instead. This script provided only for testing compatibility with Narada
95             v1.x projects.
96              
97             This script help you create skeleton project directory for using Narada
98             framework.
99              
100             Target directory shouldn't exists or must be empty.
101              
102             If target directory doesn't exists - it will be created (parent
103             directory must exists).
104              
105             If executed without param will create skeleton
106             project in current directory, which must be empty.
107              
108             Target directory become "project root directory", and all other `narada-*`
109             scripts must be executed in this directory.
110              
111             =head2 INITIAL SETUP
112              
113             File C will be initialized with value "PROJECTNAME-0.0.000",
114             where PROJECTNAME is target directory name.
115              
116             Will create C with backup of current
117             project. This backup should be used when installing this project elsewhere:
118              
119             unpack backup in empty project root
120             (if needed) unpack backup in var/patch/.prev/
121             put all updates into var/patch/
122             run narada-patch
123             setup config/* as needed for this installation
124              
125              
126             =head1 DIAGNOSTICS
127              
128             =over
129              
130             =item C<< narada-new-1: mkdir: %s >>
131              
132             Target directory wasn't exists and mkdir failed (probably parent directory
133             doesn't exist or have wrong permissions).
134              
135             =item C<< narada-new-1: not a directory: %s >>
136              
137             Script's param point to existing file.
138              
139             =item C<< narada-new-1: opendir: %s >>
140              
141             Target directory exists, but can't be read (probably have wrong permissions).
142              
143             =item C<< narada-new-1: directory not empty: %s >>
144              
145             Target directory exists, but not empty.
146              
147             =item C<< narada-new-1: unpack failed >>
148              
149             Script failed to unpack skeleton directory. Most likely reason - target
150             directory doesn't writable. While unpacking it use `tar`, so maybe there
151             some issue with it. Or this script was damaged (reinstall recommended).
152              
153             =item C<< narada-new-1: unable to detect project name >>
154              
155             Failed to setup 'config/version' file using project directory name as
156             default project name. Probably some issue with `pwd` command or unusual
157             symbols in project directory name (\n for example).
158              
159             =item C<< narada-new-1: closedir: %s >>
160              
161             =item C<< narada-new-1: chdir: %s >>
162              
163             Internal error.
164              
165             =back
166              
167              
168             =head1 CONFIGURATION AND ENVIRONMENT
169              
170             narada-new-1 requires no configuration files or environment variables.
171              
172              
173             =head1 SUPPORT
174              
175             =head2 Bugs / Feature Requests
176              
177             Please report any bugs or feature requests through the issue tracker
178             at L.
179             You will be notified automatically of any progress on your issue.
180              
181             =head2 Source Code
182              
183             This is open source software. The code repository is available for
184             public review and contribution under the terms of the license.
185             Feel free to fork the repository and submit pull requests.
186              
187             L
188              
189             git clone https://github.com/powerman/Narada.git
190              
191             =head2 Resources
192              
193             =over
194              
195             =item * MetaCPAN Search
196              
197             L
198              
199             =item * CPAN Ratings
200              
201             L
202              
203             =item * AnnoCPAN: Annotated CPAN documentation
204              
205             L
206              
207             =item * CPAN Testers Matrix
208              
209             L
210              
211             =item * CPANTS: A CPAN Testing Service (Kwalitee)
212              
213             L
214              
215             =back
216              
217              
218             =head1 AUTHOR
219              
220             Alex Efros Epowerman@cpan.orgE
221              
222              
223             =head1 COPYRIGHT AND LICENSE
224              
225             This software is Copyright (c) 2008- by Alex Efros Epowerman@cpan.orgE.
226              
227             This is free software, licensed under:
228              
229             The MIT (X11) License
230              
231              
232             =cut
233              
234             __DATA__