Showing 2 changed files with 118 additions and 112 deletions
+4 -3
gitprep.conf
... ...
@@ -20,6 +20,10 @@
20 20
 ;;; Forget to comment out after resetting password.
21 21
 ;reset_password=1
22 22
 
23
+[hypnotoad]
24
+;;; Listen URL
25
+;listen=http://*:10020
26
+
23 27
 [reverse_proxy]
24 28
 ;;; Reverse proxy support
25 29
 ;on=1
... ...
@@ -29,6 +33,3 @@
29 33
 ;;; If proxy path is http://somehost.com/foo/bar, you set path_depth to 2.
30 34
 ;path_depth=1
31 35
 ;path_depth=2
32
-
33
-[hypnotoad]
34
-listen=http://*:10020
+114 -109
lib/Gitprep.pm
... ...
@@ -1,8 +1,6 @@
1 1
 use 5.008007;
2 2
 package Gitprep;
3 3
 
4
-our $VERSION = '0.04';
5
-
6 4
 use Mojo::Base 'Mojolicious';
7 5
 use Gitprep::Git;
8 6
 use DBIx::Custom;
... ...
@@ -14,6 +12,8 @@ use Gitprep::Manager;
14 12
 use Scalar::Util 'weaken';
15 13
 use Carp 'croak';
16 14
 
15
+our $VERSION = '0.04';
16
+
17 17
 has 'git';
18 18
 has 'dbi';
19 19
 has 'validator';
... ...
@@ -22,28 +22,27 @@ has 'manager';
22 22
 sub startup {
23 23
   my $self = shift;
24 24
   
25
-  # Config
25
+  # Config file
26 26
   $self->plugin('INIConfig', {ext => 'conf'});
27 27
   
28
-  # My Config(Development)
28
+  # Config file for developper
29 29
   my $my_conf_file = $self->home->rel_file('gitprep.my.conf');
30 30
   $self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file;
31 31
   
32
-  # Config
32
+  # Listen
33 33
   my $conf = $self->config;
34
-  $conf->{hypnotoad} ||= {listen => ["http://*:10020"]};
35
-  my $listen = $conf->{hypnotoad}{listen} || '';
36
-  if ($listen ne '' && ref $listen ne 'ARRAY') {
37
-    $listen = [ split /,/, $listen ];
38
-  }
34
+  my $listen = $conf->{hypnotoad}{listen} ||= ['http://*:10020'];
35
+  $listen = [split /,/, $listen] unless ref $listen eq 'ARRAY';
39 36
   $conf->{hypnotoad}{listen} = $listen;
40 37
   
41
-  # Git command
38
+  # Git
42 39
   my $git = Gitprep::Git->new;
43
-  my $git_bin = $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin;
40
+  my $git_bin
41
+    = $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin;
44 42
   if (!$git_bin || ! -e $git_bin) {
45 43
     $git_bin ||= '';
46
-    my $error = "Can't detect or found git command ($git_bin). set git_bin in gitprep.conf";
44
+    my $error = "Can't detect or found git command ($git_bin)."
45
+      . " set git_bin in gitprep.conf";
47 46
     $self->log->error($error);
48 47
     croak $error;
49 48
   }
... ...
@@ -55,18 +54,17 @@ sub startup {
55 54
   $self->manager($manager);
56 55
   
57 56
   # Repository home
58
-  my $rep_home = $ENV{GITPREP_REP_HOME}
59
-    || $self->home->rel_file('data/rep');
57
+  my $rep_home = $ENV{GITPREP_REP_HOME} || $self->home->rel_file('data/rep');
60 58
   $git->rep_home($rep_home);
61 59
   unless (-d $rep_home) {
62 60
     mkdir $rep_home
63 61
       or croak "Can't create directory $rep_home: $!";
64 62
   }
65 63
   $self->git($git);
66
-
64
+  
67 65
   # Added public path
68 66
   push @{$self->static->paths}, $rep_home;
69
-
67
+  
70 68
   # DBI
71 69
   my $db_file = $ENV{GITPREP_DB_FILE}
72 70
     || $self->home->rel_file('data/gitprep.db');
... ...
@@ -77,7 +75,7 @@ sub startup {
77 75
   );
78 76
   $self->dbi($dbi);
79 77
   
80
-  # Change database file permision
78
+  # Database file permision
81 79
   if (my $user = $self->config->{hypnotoad}{user}) {
82 80
     my $uid = (getpwnam $user)[2];
83 81
     chown $uid, -1, $db_file;
... ...
@@ -115,112 +113,119 @@ sub startup {
115 113
   );
116 114
   
117 115
   # Helper
118
-  $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
119
-  $self->helper(finish_rendering => sub {
120
-    my $self = shift;
121
-    
122
-    $self->stash->{'mojo.routed'} = 1;
123
-    $self->rendered;
124
-    
125
-    return $self;
126
-  });
127
-  
128
-  # Routes
129
-  my $r = $self->routes;
130
-
131
-  # DBViewer(only development)
132
-  if ($self->mode eq 'development') {
133
-    eval {
134
-      $self->plugin(
135
-        'DBViewer',
136
-        dsn => "dbi:SQLite:database=$db_file"
137
-      );
138
-    };
139
-  }
140
-  
141
-  # Auto route
142 116
   {
143
-    my $r = $r->under(sub {
117
+    # API
118
+    $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
119
+    
120
+    # Finish rendering
121
+    $self->helper(finish_rendering => sub {
144 122
       my $self = shift;
145 123
       
146
-      my $api = $self->gitprep_api;
147
-      
148
-      # Admin page authentication
149
-      {
150
-        my $path = $self->req->url->path->parts->[0] || '';
151
-
152
-        if ($path eq '_admin' && !$api->logined_admin) {
153
-          $self->redirect_to('/');
154
-          return;
155
-        }
156
-      }
124
+      $self->stash->{'mojo.routed'} = 1;
125
+      $self->rendered;
157 126
       
158
-      return 1; 
127
+      return $self;
159 128
     });
160
-    $self->plugin('AutoRoute', route => $r);
161 129
   }
162
-
163
-  # User defined Routes
130
+  
131
+  # Routes
164 132
   {
165
-    # User
166
-    my $r = $r->route('/:user');
167
-    {
168
-      # Home
169
-      $r->get('/')->name('user');
170
-      
171
-      # Settings
172
-      $r->get('/_settings')->name('user-settings');
133
+    my $r = $self->routes;
134
+
135
+    # DBViewer(only development)
136
+    if ($self->mode eq 'development') {
137
+      eval {
138
+        $self->plugin(
139
+          'DBViewer',
140
+          dsn => "dbi:SQLite:database=$db_file"
141
+        );
142
+      };
173 143
     }
174 144
     
175
-    # Project
145
+    # Auto route
176 146
     {
177
-      my $r = $r->route('/:project');
178
-      
179
-      # Home
180
-      $r->get('/')->name('project');
181
-      
182
-      # Commit
183
-      $r->get('/commit/*diff')->name('commit');
184
-      
185
-      # Commits
186
-      $r->get('/commits/*rev_file', {file => undef})->name('commits');
187
-      
188
-      # Branches
189
-      $r->any('/branches/*base_branch', {base_branch => undef})->name('branches');
147
+      my $r = $r->under(sub {
148
+        my $self = shift;
149
+        
150
+        my $api = $self->gitprep_api;
151
+        
152
+        # Admin page authentication
153
+        {
154
+          my $path = $self->req->url->path->parts->[0] || '';
190 155
 
191
-      # Tags
192
-      $r->get('/tags');
156
+          if ($path eq '_admin' && !$api->logined_admin) {
157
+            $self->redirect_to('/');
158
+            return;
159
+          }
160
+        }
161
+        
162
+        return 1; 
163
+      });
164
+      $self->plugin('AutoRoute', route => $r);
165
+    }
193 166
 
194
-      # Tree
195
-      $r->get('/tree/*rev_dir', {dir => undef})->name('tree');
196
-      
197
-      # Blob
198
-      $r->get('/blob/*rev_file', {file => undef})->name('blob');
199
-      
200
-      # Raw
201
-      $r->get('/raw/*rev_file', {file => undef})->name('raw');
202
-      
203
-      # Archive
204
-      $r->get('/archive/(*rev).tar.gz')->to(archive_type => 'tar')->name('archive');
205
-      $r->get('/archive/(*rev).zip')->to(archive_type => 'zip')->name('archive');
206
-      
207
-      # Compare
208
-      $r->get('/compare/(*rev1)...(*rev2)')->name('compare');
209
-      
210
-      # Settings
211
-      $r->any('/settings');
167
+    # Custom routes
168
+    {
169
+      # User
170
+      my $r = $r->route('/:user');
171
+      {
172
+        # Home
173
+        $r->get('/')->name('user');
174
+        
175
+        # Settings
176
+        $r->get('/_settings')->name('user-settings');
177
+      }
212 178
       
213
-      # Fork
214
-      $r->any('/fork');
179
+      # Project
180
+      {
181
+        my $r = $r->route('/:project');
182
+        
183
+        # Home
184
+        $r->get('/')->name('project');
185
+        
186
+        # Commit
187
+        $r->get('/commit/*diff')->name('commit');
188
+        
189
+        # Commits
190
+        $r->get('/commits/*rev_file', {file => undef})->name('commits');
191
+        
192
+        # Branches
193
+        $r->any('/branches/*base_branch', {base_branch => undef})->name('branches');
215 194
 
216
-      # Network
217
-      $r->get('/network');
195
+        # Tags
196
+        $r->get('/tags');
218 197
 
219
-      # Network Graph
220
-      $r->get('/network/graph/(*rev1)...(*rev2_abs)')->name('network/graph');
221
-      
222
-      # Get branches and tags
223
-      $r->get('/api/revs')->name('api/revs');
198
+        # Tree
199
+        $r->get('/tree/*rev_dir', {dir => undef})->name('tree');
200
+        
201
+        # Blob
202
+        $r->get('/blob/*rev_file', {file => undef})->name('blob');
203
+        
204
+        # Raw
205
+        $r->get('/raw/*rev_file', {file => undef})->name('raw');
206
+        
207
+        # Archive
208
+        $r->get('/archive/(*rev).tar.gz')->to(archive_type => 'tar')->name('archive');
209
+        $r->get('/archive/(*rev).zip')->to(archive_type => 'zip')->name('archive');
210
+        
211
+        # Compare
212
+        $r->get('/compare/(*rev1)...(*rev2)')->name('compare');
213
+        
214
+        # Settings
215
+        $r->any('/settings');
216
+        
217
+        # Fork
218
+        $r->any('/fork');
219
+
220
+        # Network
221
+        $r->get('/network');
222
+
223
+        # Network Graph
224
+        $r->get('/network/graph/(*rev1)...(*rev2_abs)')->name('network/graph');
225
+        
226
+        # Get branches and tags
227
+        $r->get('/api/revs')->name('api/revs');
228
+      }
224 229
     }
225 230
   }
226 231