Skip to content

Commit 4c3f3df

Browse files
committed
first import
0 parents  commit 4c3f3df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1884
-0
lines changed

Changes

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This file documents the revision history for Perl extension Tweetalyst::Web.
2+
3+
0.01 2010-06-15 13:57:56
4+
- initial revision, generated by Catalyst

Makefile.PL

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env perl
2+
# IMPORTANT: if you delete this file your app will not work as
3+
# expected. You have been warned.
4+
use inc::Module::Install;
5+
use Module::Install::Catalyst; # Complain loudly if you don't have
6+
# Catalyst::Devel installed or haven't said
7+
# 'make dist' to create a standalone tarball.
8+
9+
name 'Tweetalyst-Web';
10+
all_from 'lib/Tweetalyst/Web.pm';
11+
12+
requires 'Catalyst::Runtime' => '5.80024';
13+
requires 'Catalyst::Plugin::ConfigLoader';
14+
requires 'Catalyst::Plugin::Static::Simple';
15+
requires 'Catalyst::Action::RenderView';
16+
requires 'Catalyst::Plugin::Session::Store::FastMmap';
17+
requires 'Catalyst::View::JSON';
18+
requires 'Moose';
19+
requires 'namespace::autoclean';
20+
requires 'Config::General'; # This should reflect the config file format you've chosen
21+
# See Catalyst::Plugin::ConfigLoader for supported formats
22+
test_requires 'Test::More' => '0.88';
23+
catalyst;
24+
25+
install_script glob('script/*.pl');
26+
auto_install;
27+
WriteAll;

README

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Tweetalyst
2+
3+
Quick & Dirty Catalyst port of http://github.com/garu/tweetylicious
4+
5+
This is not stable and may have flaws. :|
6+
Use only for testing and learning purposes.
7+
8+
Run script/tweetalyst_web_server.pl to test the application.

_WORK_LOG.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
catalyst.pl Tweetalyst::Web
2+
cd Tweetalyst-Web/
3+
mkdir db
4+
cd db/
5+
vim tweetalyst.sql
6+
sqlite3 tweetalyst.db < tweetalyst.sql
7+
cd ..
8+
script/tweetalyst_web_create.pl view TT TT
9+
[ Add Unicode::Encoding to Tweetalyst/Web.pm ]
10+
script/tweetalyst_web_create.pl model DBIC DBIC::Schema Tweetalyst::Schema create=static dbi:SQLite:db/tweetalyst.db
11+
12+
script/tweetalyst_web_create.pl view JSON JSON
13+
tweetalyst_web.conf 에 default_view TT 추가

db/tweetalyst.db

11 KB
Binary file not shown.

db/tweetalyst.sql

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CREATE TABLE user (
2+
username TEXT NOT NULL UNIQUE PRIMARY KEY,
3+
password TEXT NOT NULL,
4+
email TEXT,
5+
gravatar TEXT,
6+
bio TEXT
7+
);
8+
9+
CREATE TABLE post (
10+
id INTEGER NOT NULL PRIMARY KEY
11+
ASC AUTOINCREMENT,
12+
username TEXT NOT NULL
13+
CONSTRAINT fk_user_username
14+
REFERENCES user(username)
15+
ON DELETE CASCADE,
16+
content TEXT NOT NULL,
17+
date INTEGER NOT NULL
18+
);
19+
20+
CREATE TABLE follow (
21+
id INTEGER NOT NULL PRIMARY KEY
22+
ASC AUTOINCREMENT,
23+
source TEXT NOT NULL
24+
CONSTRAINT fk_user_username
25+
REFERENCES user(username)
26+
ON DELETE CASCADE,
27+
destination TEXT NOT NULL
28+
CONSTRAINT fk_user_username2
29+
REFERENCES user(username)
30+
ON DELETE CASCADE
31+
);

lib/Tweetalyst/API.pm

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package Tweetalyst::API;
2+
use Moose;
3+
use Tweetalyst::Schema;
4+
use namespace::autoclean;
5+
6+
with qw/Tweetalyst::Trait::WithAPI Tweetalyst::Trait::WithDBIC/;
7+
8+
sub _build_schema {
9+
my $self = shift;
10+
return Tweetalyst::Schema->connect( @{ $self->connect_info } );
11+
}
12+
13+
sub _build_apis {
14+
my $self = shift;
15+
16+
my %apis;
17+
foreach my $module ( qw/Follow Post User/ ) {
18+
my $class = "Tweetalyst::API::$module";
19+
if (! Class::MOP::is_class_loaded($class)) {
20+
Class::MOP::load_class($class);
21+
}
22+
23+
$apis{ $module } = $class->new(schema => $self->schema);
24+
}
25+
26+
return \%apis;
27+
}
28+
29+
__PACKAGE__->meta->make_immutable();
30+
31+
1;
32+

lib/Tweetalyst/API/Follow.pm

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package Tweetalyst::API::Follow;
2+
use Moose;
3+
use namespace::autoclean;
4+
5+
with 'Tweetalyst::API::WithDBIC';
6+
7+
__PACKAGE__->meta->make_immutable();
8+
9+
sub is_a_following_b {
10+
my ($self, $a, $b) = @_;
11+
return $self->resultset->search( { source => $a, destination => $b } )->count;
12+
}
13+
1;

lib/Tweetalyst/API/Post.pm

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package Tweetalyst::API::Post;
2+
use Moose;
3+
use namespace::autoclean;
4+
5+
with 'Tweetalyst::API::WithDBIC';
6+
7+
# this returns our search results
8+
sub search_posts {
9+
my ($self,@item_to_search) = @_;
10+
my @condition;
11+
foreach (@item_to_search) {
12+
push @condition, ( 'posts.content' => { like => "%$_%" } );
13+
}
14+
my $rs = $self->resultset('User')->search(
15+
{
16+
-or => [ @condition ],
17+
},
18+
{
19+
join => 'posts',
20+
select => [qw/me.username posts.id me.gravatar
21+
posts.content posts.date/],
22+
as => [qw/username id gravatar content date/],
23+
order_by => ['posts.date'],
24+
},
25+
);
26+
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
27+
return [ $rs->all ];
28+
}
29+
30+
# this returns sorted posts from all users in @users
31+
sub fetch_posts_by {
32+
my ($self,@users) = @_;
33+
my @condition;
34+
foreach (@users) {
35+
push @condition, ( 'me.username' => $_ );
36+
}
37+
my $rs = $self->resultset('User')->search(
38+
{
39+
-or => [ @condition ],
40+
},
41+
{
42+
join => 'posts',
43+
select => [qw/me.username posts.id me.gravatar
44+
posts.content posts.date/],
45+
as => [qw/username id gravatar content date/],
46+
order_by => ['posts.date'],
47+
},
48+
);
49+
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
50+
return [ $rs->all ];
51+
}
52+
53+
__PACKAGE__->meta->make_immutable();
54+
55+
1;

lib/Tweetalyst/API/User.pm

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package Tweetalyst::API::User;
2+
use Moose;
3+
use Digest::SHA1 qw/sha1_hex/;
4+
use namespace::autoclean;
5+
6+
with 'Tweetalyst::API::WithDBIC';
7+
8+
#sub _build_resultset_constraints { return +{ username => {like => 'test%'} } };
9+
10+
# this returns who follows our user.
11+
# # Each element is a hash of usernames and gravatars
12+
sub get_followers_for {
13+
my ($self, $user) = @_;
14+
my $rs = $self->resultset->search(
15+
{
16+
'follow_sources.destination' => $user
17+
},
18+
{
19+
join => 'follow_sources',
20+
select => [qw/username gravatar/],
21+
},
22+
);
23+
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
24+
my %hash;
25+
while ( my $row = $rs->next ) {
26+
$hash{$row->{username}} = $row;
27+
}
28+
return \%hash;
29+
30+
# return Model->selectall_hashref(
31+
# 'SELECT username, gravatar FROM user, follow
32+
#WHERE user.username = follow.source
33+
#AND follow.destination = ?',
34+
# 'username', {} , $_[0],
35+
# );
36+
}
37+
38+
# this returns who our user follows
39+
sub get_followed_by {
40+
my ($self, $user) = @_;
41+
my $rs = $self->resultset->search(
42+
{
43+
'follow_destinations.source' => $user
44+
},
45+
{
46+
join => 'follow_destinations',
47+
select => [qw/username gravatar/],
48+
},
49+
);
50+
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
51+
my %hash;
52+
while ( my $row = $rs->next ) {
53+
$hash{$row->{username}} = $row;
54+
}
55+
return \%hash;
56+
# return Model->selectall_hashref(
57+
# 'select username, gravatar from user, follow
58+
#where user.username = follow.destination
59+
#and follow.source = ?',
60+
# 'username', {}, $_[0],
61+
# );
62+
}
63+
64+
sub validate {
65+
my ($self, $user, $pass, $pass2, $routes) = @_;
66+
return 'username field must not be blank' unless $user && length $user;
67+
return 'password field must not be blank' unless $pass && length $pass;
68+
return 'please re-type your password' unless $pass2 && length $pass2;
69+
return "passwords don't match" unless $pass eq $pass2;
70+
return 'sorry, this user already exists'
71+
if $self->resultset->find($user);
72+
73+
# let's not allow usernames that are part of a valid route
74+
#return 'sorry, invalid username'
75+
#if grep { length $_->name && index($user, $_->name) == 0 } @$routes;
76+
77+
return;
78+
79+
80+
}
81+
82+
sub create_user {
83+
my ($self, $username, $password, $email, $gravatar, $bio) = @_;
84+
85+
$self->resultset->create({
86+
username => $username,
87+
password => sha1_hex($password),
88+
email => $email,
89+
gravatar => sha1_hex($gravatar),
90+
bio => $bio,
91+
});
92+
}
93+
94+
__PACKAGE__->meta->make_immutable();
95+
96+
1;

lib/Tweetalyst/API/WithDBIC.pm

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package Tweetalyst::API::WithDBIC;
2+
use Moose::Role;
3+
use namespace::autoclean;
4+
5+
with 'Tweetalyst::Trait::WithDBIC' => {
6+
-excludes => '_build_default_moniker',
7+
};
8+
# You can add a cache layer here.
9+
10+
sub _build_default_moniker {
11+
if ((blessed $_[0]) =~ /API::(.+)$/) {
12+
return $1;
13+
}
14+
return;
15+
}
16+
17+
1;

lib/Tweetalyst/Schema.pm

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package Tweetalyst::Schema;
2+
3+
# Created by DBIx::Class::Schema::Loader
4+
# DO NOT MODIFY THE FIRST PART OF THIS FILE
5+
6+
use strict;
7+
use warnings;
8+
9+
use base 'DBIx::Class::Schema';
10+
11+
__PACKAGE__->load_namespaces;
12+
13+
14+
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2010-06-15 14:41:11
15+
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yi1FApLbBA6lhCTjFuYcSQ
16+
17+
18+
# You can replace this text with custom content, and it will be preserved on regeneration
19+
1;

0 commit comments

Comments
 (0)