added create_fullqualified_m...
|
1 |
use strict; |
2 |
use warnings; |
|
3 | ||
4 |
use FindBin; |
|
5 |
use File::Basename qw/basename fileparse/; |
|
6 |
use File::Copy 'copy'; |
|
support model full-qualified...
|
7 |
use File::Path 'mkpath'; |
added create_fullqualified_m...
|
8 | |
9 |
my $top = $FindBin::Bin; |
|
10 |
my $common = "$top/common"; |
|
11 |
my $common_fullqualified = "$top/common_fullqualified"; |
|
12 |
mkdir $common_fullqualified unless -d $common_fullqualified; |
|
13 | ||
14 |
my @modules = grep { -f $_ } glob("$common/*"); |
|
15 |
for my $module (@modules) { |
|
16 |
my $module_base = basename $module; |
|
17 |
copy $module, "$common_fullqualified/$module_base" |
|
18 |
or die "Can't move module file: $!"; |
|
19 |
} |
|
20 | ||
21 |
my @dirs = grep { -d $_ } glob("$FindBin::Bin/common/*"); |
|
22 |
for my $dir (@dirs) { |
|
23 |
my $base_dir = basename $dir; |
|
24 |
my $model_dir_fullqualified = "$common_fullqualified/$base_dir"; |
|
25 |
mkdir $model_dir_fullqualified unless -d $model_dir_fullqualified; |
|
26 |
|
|
27 |
my @files = grep { /table\d\.pm/ } glob("$dir/*"); |
|
28 |
for my $file (@files) { |
|
29 |
|
|
added t/common-mysql-qualifi...
|
30 |
for my $database (qw/main dbix_custom/) { |
support model full-qualified...
|
31 | |
added t/common-mysql-qualifi...
|
32 |
my $content = do { |
33 |
open my $fh, '<', $file; |
|
34 |
local $/; |
|
35 |
<$fh>; |
|
36 |
}; |
|
37 |
|
|
38 |
$content =~ s/::table(\d)/::${database}::table$1/g; |
|
39 |
$content =~ s/([^:])table(\d)/$1$database.table$2/g; |
|
40 |
|
|
41 |
mkpath "$common_fullqualified/$base_dir/$database"; |
|
42 |
my $base_name = (fileparse($file, qr/\..+$/))[0]; |
|
43 |
$base_name = $base_name; |
|
44 |
my $new_file = "$common_fullqualified/$base_dir/$database/$base_name.pm"; |
|
45 |
|
|
46 |
open my $fh, '>', $new_file |
|
47 |
or die "Can't write file: $!"; |
|
48 |
|
|
49 |
print $fh $content; |
|
50 |
} |
|
added create_fullqualified_m...
|
51 |
} |
52 |
} |