line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::FileThing::Cloner; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
6
|
|
|
|
|
|
|
# Nigel Hamilton |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
9
|
|
|
|
|
|
|
# All Rights Reserved |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
12
|
|
|
|
|
|
|
# Filename: Goo::FileThing::Cloner.pm |
13
|
|
|
|
|
|
|
# Description: Really simple Cloner |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Date Change |
16
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
# 01/8/2005 Version 1 |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
7009
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use Goo::Object; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
24
|
1
|
|
|
1
|
|
7
|
use Goo::Header; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
25
|
1
|
|
|
1
|
|
5
|
use Goo::Prompter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
5
|
use base qw(Goo::Object); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
674
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
# run - create the output file |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
############################################################################### |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub run { |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
1
|
|
my ($this, $thing) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
unless ($thing->isa("Goo::FileThing")) { |
41
|
0
|
|
|
|
|
|
Goo::Prompter::say("The FileCloner can only clone a Goo::FileThing."); |
42
|
0
|
|
|
|
|
|
Goo::Prompter::notify("Specify a different action handler in the .goo config file."); |
43
|
0
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# show the header |
47
|
0
|
|
|
|
|
|
Goo::Header::show("Clone", $thing->get_filename(), $thing->get_full_path()); |
48
|
0
|
|
|
|
|
|
Goo::Prompter::say(); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $source_file = $thing->get_filename(); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# find out what we're cloning to ... |
53
|
0
|
|
|
|
|
|
my $destination_file = Goo::Prompter::ask("Clone $source_file to?"); |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
unless ($destination_file) { |
56
|
0
|
|
|
|
|
|
Goo::Prompter::notify("No Thing to clone $source_file to."); |
57
|
0
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# put the cloned Thing in the same location |
61
|
0
|
|
|
|
|
|
my $destination_path = $thing->get_location() . "/" . $destination_file; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (-e $destination_path) { |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# check if some Thing is there already? |
66
|
|
|
|
|
|
|
return |
67
|
0
|
0
|
|
|
|
|
unless (Goo::Prompter::confirm("$destination_file already exists. Continue?", "N")); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $file_string = $thing->get_file(); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# I often want to replace the filename - default to this first time around |
73
|
0
|
|
|
|
|
|
my $original_text = $thing->get_prefix(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# do find and replace |
76
|
0
|
|
|
|
|
|
while ($original_text = Goo::Prompter::ask("Enter text to replace?", $original_text)) { |
77
|
0
|
|
|
|
|
|
my $new_text = Goo::Prompter::ask("Replace $original_text with?"); |
78
|
0
|
|
|
|
|
|
$file_string =~ s/$original_text/$new_text/g; |
79
|
0
|
|
|
|
|
|
$original_text = ""; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
Goo::Prompter::yell("Finished cloning $thing->{filename} to $destination_file."); |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if (Goo::Prompter::confirm("Save $destination_file?")) { |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# write the cloned Thing |
87
|
0
|
|
|
|
|
|
Goo::FileUtilities::write_file($destination_path, $file_string); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Goo::FileThing::Cloner - Simply clone one file to another |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Goo::FileThing::Cloner; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 DESCRIPTION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 METHODS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item run |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
create the output file |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO |
125
|
|
|
|
|
|
|
|