root/Mixxi/trunk/lib/Mixxi/Schema/Url.pm

Revision 2067 (checked in by miyagawa, 14 years ago)

import Mixxi tinyurl

Line 
1 package Mixxi::Schema::Url;
2
3 # Created by DBIx::Class::Schema::Loader v0.03008 @ 2006-11-02 02:00:14
4
5 use strict;
6 use warnings;
7
8 use base 'DBIx::Class';
9
10 __PACKAGE__->load_components("PK::Auto", "Core");
11 __PACKAGE__->table("url");
12 __PACKAGE__->add_columns(
13   "id",
14   { data_type => "integer", is_nullable => 0, size => undef },
15   "url",
16   { data_type => "varchar", is_nullable => 0, size => 255 },
17   "alias",
18   { data_type => "varchar", is_nullable => 0, size => 16 },
19 );
20 __PACKAGE__->set_primary_key("id");
21
22 use Number::RecordLocator;
23 my $encoder = Number::RecordLocator->new;
24
25 sub id_enc {
26     my $self = shift;
27     $encoder->encode($self->id);
28 }
29
30 sub to_id {
31     my($class, $enc) = @_;
32     $encoder->decode($enc);
33 }
34
35 sub canonical {
36     my $self = shift;
37
38     my $base = Mixxi->config->{tinyurl_base};
39     if ($self->alias) {
40         return $base . $self->alias;
41     } else {
42         return $base . "u/" . $self->id_enc;
43     }
44 }
45
46 1;
47
Note: See TracBrowser for help on using the browser.