root/veekun/trunk/script/utils/schema-cleanup.pl

Revision 404, 1.6 kB (checked in by eevee, 11 months ago)

Bit of a shoutbox test. Not particularly amazing. For the life of me I can't figure out how to log in and stay that way. (#152)
Tossing in my schema cleanup script, too. Ugh dirty mixed commits~

Line 
1use strict;
2use warnings;
3
4my %done = map { $_ => 1 } qw/
5
6      Abilities.pm
7      Berries.pm
8      EvChains.pm
9      Pokemon.pm
10      Edits.pm
11      Forums.pm
12      Items.pm
13      Creators.pm
14      ItemKeywords.pm
15      ContestMoves.pm
16      ErrorLog.pm
17      FlavorText.pm
18      Gallery.pm
19/;
20
21for my $file (glob('*.pm')) {
22#for my $file ('ItemKeywords.pm') {
23    next if $done{$file};
24
25    open my $fh, '<', $file;
26    binmode $fh;
27    my $contents = join '', <$fh>;
28    close $fh;
29
30    my $package = $file;
31    $package =~ s/\.pm$//;
32
33    $contents =~ s/# Created by DBIx::Class::Schema::Loader v.*\n\n//;
34    $contents =~ s/^.+add_unique_constraint.+undef.*\n//mg;
35    $contents =~ s/warnings;\n\nuse base/warnings;\nuse base/;
36    $contents =~ s/__PACKAGE__->table\("(.+)"\);/__PACKAGE__->table('$1');/;
37    my $table = $1;
38    $contents =~ s/__PACKAGE__->load_components\("PK::Auto", "Core"\);/__PACKAGE__->load_components('Core');/;
39    $contents =~ s/__PACKAGE__->set_primary_key\("id"\);/__PACKAGE__->set_primary_key('id');/;
40    $contents =~ s/Class';\n/Class';
41
42=head1 NAME
43
44Vee::Schema::$package - DBIC class for the C<$table> table
45
46=cut
47/;
48    $contents =~ s/1;\n\n\z/=head1 SEE ALSO
49
50L<Vee::Schema>, L<DBIx::Class>
51
52=head1 AUTHOR
53
54Maintainer: Alex "Eevee" Munroe (C<veekun\@veekun.com>)
55
56See the included F<AUTHORS> file for a full list of contributers.
57
58=head1 LICENSE
59
60See the included F<LICENSE> file.
61
62=cut
63
641;
65/;
66
67    $contents =~ s/(__PACKAGE__->.+\()"((?:\w+", ")+\w+)"(\);)/ my ($b, $m, $e) = ($1, $2, $3); $m =~ s[", "][ ]g; $b.'qw\/ '.$m.' \/'.$e /eg;
68
69    open my $fh_out, '>', $file;
70    binmode $fh_out;
71    print $fh_out $contents;
72    close $fh_out;
73}
Note: See TracBrowser for help on using the browser.