-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vti
committed
Apr 11, 2011
1 parent
672b9bd
commit 9d2bfc5
Showing
16 changed files
with
218 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package Look2RemoveMe::Action::Index; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use base 'Lamework::Action'; | ||
|
||
use Try::Tiny; | ||
use Lamework::Exception; | ||
|
||
use Look2RemoveMe::File; | ||
|
||
sub run { | ||
my $self = shift; | ||
|
||
$self->set_var(type => 'image'); | ||
|
||
my $upload = $self->req->upload('image'); | ||
|
||
return $self->set_var('errors' => {image => 'Required'}) unless $upload; | ||
|
||
try { | ||
Lamework::Exception->throw("Doesn't look like an image to me") | ||
unless $upload->content_type =~ m{^image/}; | ||
|
||
my $max_size_in_megs = 1; | ||
if ($upload->size > $max_size_in_megs * 1024 * 1024) { | ||
Lamework::Exception->throw( | ||
"File size is too big (max $max_size_in_megs Mb)"); | ||
} | ||
|
||
my $image = Look2RemoveMe::File->create_from_path($upload->path); | ||
|
||
$self->set_var(url => $self->url_for('view', id => $image->id)); | ||
$self->set_template('upload_success'); | ||
} | ||
catch { | ||
my $e = $_; | ||
|
||
die $e unless $e->isa('Lamework::Exception'); | ||
|
||
$self->set_var('errors' => {image => $e->error}); | ||
}; | ||
} | ||
|
||
1; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package Look2RemoveMe::Counter; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Lamework::Registry; | ||
|
||
sub new { | ||
my $class = shift; | ||
|
||
my $self = {}; | ||
bless $self, $class; | ||
|
||
return $self; | ||
} | ||
|
||
sub total { | ||
my $self = shift; | ||
|
||
return int $self->_slurp; | ||
} | ||
|
||
sub increment { | ||
my $self = shift; | ||
|
||
my $total = $self->total; | ||
open my $file, '>', $self->_path or die $!; | ||
print $file $total + 1; | ||
|
||
return $self; | ||
} | ||
|
||
sub _slurp { | ||
my $self = shift; | ||
|
||
open my $file, '<', $self->_path or return '0'; | ||
return do {local $/; <$file>}; | ||
} | ||
|
||
sub _path { | ||
my $self = shift; | ||
|
||
my $home = Lamework::Registry->get('home'); | ||
|
||
return $home->catfile('counter.txt'); | ||
} | ||
|
||
1; |
Oops, something went wrong.