line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::FileSummoner::CreateFile; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
19
|
$App::FileSummoner::CreateFile::VERSION = '0.005'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
524
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Template; |
8
|
|
|
|
|
|
|
use File::Spec; |
9
|
|
|
|
|
|
|
use File::Basename qw/ fileparse /; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use App::FileSummoner::SkeletonDirsFinder; |
12
|
|
|
|
|
|
|
use App::FileSummoner::Register qw(chooseSkeleton registerSkeleton); |
13
|
|
|
|
|
|
|
use App::FileSummoner::Register::Rules; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
App::FileSummoner::CreateFile - The great new App::FileSummoner::CreateFile! |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $summoner = App::FileSummoner::CreateFile->new(); |
22
|
|
|
|
|
|
|
$summoner->summonFile('some/path/file.ext'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 summonFile |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Create file using best possible skeleton. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub summonFile { |
33
|
|
|
|
|
|
|
my ($self, $fileName) = @_; |
34
|
|
|
|
|
|
|
return $self->summonFileTo($fileName, $fileName); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 summonFileToStdout |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Print best possible skeleton for a given file to STDOUT. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub summonFileToStdout { |
44
|
|
|
|
|
|
|
my ($self, $fileName) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $buffer; |
47
|
|
|
|
|
|
|
$self->summonFileTo($fileName, \$buffer); |
48
|
|
|
|
|
|
|
print $buffer; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# TODO: refactor this beast |
52
|
|
|
|
|
|
|
sub summonFileTo { |
53
|
|
|
|
|
|
|
my ($self, $fileName, $target) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$fileName = File::Spec->rel2abs( $fileName ); |
56
|
|
|
|
|
|
|
my @skeletonDirs = |
57
|
|
|
|
|
|
|
App::FileSummoner::SkeletonDirsFinder->new->findForFile( $fileName ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->loadRules(@skeletonDirs); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $template = Template->new( |
62
|
|
|
|
|
|
|
INCLUDE_PATH => [@skeletonDirs], |
63
|
|
|
|
|
|
|
TRIM => 1, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $skeleton = chooseSkeleton( $fileName ) |
67
|
|
|
|
|
|
|
|| die "Couldn't find suitable skeleton for " . $fileName; |
68
|
|
|
|
|
|
|
print STDERR "Skeleton: " . $skeleton . "\n"; |
69
|
|
|
|
|
|
|
$template->process( $skeleton, $self->templateVarsForFile($fileName), |
70
|
|
|
|
|
|
|
$target ) |
71
|
|
|
|
|
|
|
|| die $template->error . "\n"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 templateVarsForFile |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Return template variables for given filename. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
name => 'file name without extension', |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub templateVarsForFile { |
85
|
|
|
|
|
|
|
my ($self, $fileName) = @_; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my ($name) = fileparse($fileName, qr/\.[^.]*/); |
88
|
|
|
|
|
|
|
return { name => $name }; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 loadRules |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Load rules from I<rules.pl> files located in skeleton directories. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub loadRules { |
98
|
|
|
|
|
|
|
my ( $self, @skeletonDirs ) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
foreach my $dir (@skeletonDirs) { |
101
|
|
|
|
|
|
|
my $rules = $dir . "/rules.pl"; |
102
|
|
|
|
|
|
|
if ( -e $rules ) { |
103
|
|
|
|
|
|
|
do $rules || die $@; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Marian Schubert, C<< <marian.schubert at gmail.com> >> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 BUGS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-file-skeleton at rt.cpan.org>, or through |
115
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Skeleton>. I will be notified, and then you'll |
116
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SUPPORT |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
perldoc App::FileSummoner::CreateFile |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
You can also look for information at: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Skeleton> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L<http://annocpan.org/dist/File-Skeleton> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * CPAN Ratings |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/File-Skeleton> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * Search CPAN |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/File-Skeleton/> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Copyright 2011 Marian Schubert. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
157
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
158
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; # End of App::FileSummoner::CreateFile |