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

Revision 350, 2.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::Items;
2
3use strict;
4use warnings;
5use base 'DBIx::Class';
6
7=head1 NAME
8
9Vee::Schema::Items - DBIC class for the C<items> table
10
11=cut
12
13__PACKAGE__->load_components('Core');
14__PACKAGE__->table('items');
15__PACKAGE__->add_columns(qw/ id game_id berry_id name category cost col5 hp_plus_maybe fling_power fling_effect natural_gift_power natural_gift_type col12 col13 col14 col15 col16 col17 col18 col19 col20 col21 col22 col23 effort_hp effort_at effort_de effort_sp effort_sa effort_sd hp_restored pp_restored happiness1 happiness2 happiness3 is_underground dpblurb description /);
16__PACKAGE__->set_primary_key('id');
17
18__PACKAGE__->has_many(pokemon_items => 'Vee::Schema::PokemonItems', 'item_id', { join_type => 'left' });
19__PACKAGE__->many_to_many(pokemon => 'pokemon_items', 'pokemon');
20
21__PACKAGE__->might_have(berry => 'Vee::Schema::Berries', { 'foreign.id' => 'self.berry_id' });
22
23=head1 METHODS
24
25=head2 display_name
26
27Returns this item's name, suitable for display.  This method actually just
28replaces 'Poke' with 'Pok&eacute;', as the database is not currently designed
29for Unicode.
30
31=cut
32
33sub display_name {
34    my ($self) = @_;
35
36    my $name = $self->name;
37    $name =~ s/Poke/Pok&eacute;/;
38    return $name;
39}
40
41=head2 display_name
42
43Returns the filename (sans extension) for this item's sprite.
44
45=cut
46
47sub sprite_name {
48    my ($self) = @_;
49
50    my $name = lc $self->name;
51    # TMs!
52
53    $name =~ tr/ /-/;
54    $name =~ tr/-a-z0-9//cd;
55
56    return $name;
57}
58
59=head2 fling_description
60
61Returns the effect this item will cause when Fling is used with it.
62
63=cut
64
65sub fling_description {
66    my ($self) = @_;
67
68    return 'n/a' if not $self->fling_power;
69
70    my $desc = 'Inflicts regular damage with ' . $self->fling_power . ' power.';
71    $desc .= '  ' . $self->fling_effect
72        if $self->fling_effect;
73
74    return $desc;
75}
76
77=head1 SEE ALSO
78
79L<Vee::Schema>, L<DBIx::Class>
80
81=head1 AUTHOR
82
83Maintainer: Alex "Eevee" Munroe (C<veekun@veekun.com>)
84
85See the included F<AUTHORS> file for a full list of contributers.
86
87=head1 LICENSE
88
89See the included F<LICENSE> file.
90
91=cut
92
931;
Note: See TracBrowser for help on using the browser.