root/veekun/trunk/lib/Vee/Schema/Moves.pm @ 350

Revision 350, 3.0 KB (checked in by eevee, 2 years ago)

I discovered that DBIx::Class::Schema::Loader had been filling my table classes with lines of the form __PACKAGE__->add_unique_constraint(['id'], undef); erroneously, due to someone's inadvertently iterating over %hash rather than keys %hash. Not only were these lines redundant in the case of a primary key, but the parameters are supposed to be a name and a list of columns: thus I had a lot of constraints with ARRAY(0x...) as names and no columns. This was thoroughly breaking $schema->deploy, as it was trying to create indices with garbage names that looked like functions. I have, obviously, removed them all.
In the process, I have done something I've been meaning to do for a while: cleaned up the source in every single file to match my usual style. No auto-gen comment, no redundant loading of PK::Auto, no double-newline after the 1;, proper POD, use of qw// for passing lists, etc. This is actually a teeny part of my db cleanup tracking bug. (#58)

Line 
1package Vee::Schema::Moves;
2
3use strict;
4use warnings;
5use base 'DBIx::Class';
6
7=head1 NAME
8
9Vee::Schema::Moves - DBIC class for the C<moves> table
10
11=cut
12
13__PACKAGE__->load_components('Core');
14__PACKAGE__->table('moves');
15__PACKAGE__->add_columns(qw/
16    id
17    name
18    name_jp
19    name_romaji
20    type
21    power
22    pp
23    acc
24    target
25    class
26    flags
27    combos
28    effect_chance
29    kind
30    status
31    move_effect_id
32    gameblurb
33    dpblurb
34    contype
35    coneffect
36    notes
37/);
38__PACKAGE__->set_primary_key('id');
39
40__PACKAGE__->belongs_to(contest => 'Vee::Schema::ContestMoves', 'coneffect');
41__PACKAGE__->belongs_to(effect => 'Vee::Schema::MoveEffects', 'move_effect_id');
42__PACKAGE__->has_many(pokemoves => 'Vee::Schema::PokeMoves', 'moveid');
43
44=head1 METHODS
45
46=head2 priority
47
48Returns the priority of the given move.  Only exists for consistency, as this
49is the only data commonly accessed via C<%MoveData> that is actually a column
50of C<move_effects>.
51
52=cut
53
54sub priority {
55    my ($self) = @_;
56    return $self->effect->priority;
57}
58
59=head2 description
60
61Returns the full description for this move.  Applies C<_format_description>
62effects, and converts tab-delimited tables to HTML.
63
64=cut
65
66sub description {
67    my ($self) = @_;
68
69    my $desc = $self->_format_description( $self->effect->description );
70    my @lines = split /\n/, $desc;
71
72    my $table_open = 0;
73    for my $line (@lines) {
74        if ($line =~ /\t/) {
75            $line =~ s[\t][</td><td>]g;
76            $line = "<tr><td>$line</td></tr>";
77            $line = "<table>\n$line" if not $table_open;
78            $table_open = 1;
79        } else {
80            $line = "<p>$line</p>";
81            $line = "</table>\n$line" if $table_open;
82            $table_open = 0;
83        }
84    }
85    push @lines, "</table>" if $table_open;
86
87    return join "\n", @lines;
88}
89
90=head2 blurb
91
92Returns a short blurb for this move, suitable for putting in a move table.
93Applies C<_format_description> effects.
94
95If this move's move effect has no blurb, the full description will be used
96instead.  This should no longer happen, but was necessary for some degree of
97completion when the blurbs were still being written.
98
99=cut
100
101sub blurb {
102    my ($self) = @_;
103
104    return $self->_format_description(
105        $self->effect->blurb || $self->effect->description
106    );
107}
108
109=head2 _format_description($text)
110
111Inserts this move's effect chance and priority into the provided string, if
112applicable.  Used by C<description> and C<blurb>.
113
114=cut
115
116sub _format_description {
117    my ($self, $text) = @_;
118
119    # effect chance
120    $text =~ s/a chance to/a ${\( $self->effect_chance )}% chance to/g
121        if $self->effect_chance;
122
123    if ($self->effect->priority < 0) {
124        $text = "Goes last.  $text";
125    } elsif ($self->effect->priority > 0) {
126        $text = "Goes first.  $text";
127    }
128
129    return $text;
130}
131
132=head1 SEE ALSO
133
134L<Vee::Schema>, L<DBIx::Class>
135
136=head1 AUTHOR
137
138Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>)
139
140See the included F<AUTHORS> file for a full list of contributers.
141
142=head1 LICENSE
143
144See the included F<LICENSE> file.
145
146=cut
147
1481;
Note: See TracBrowser for help on using the browser.