12 |
|
|
13 |
use Perly::Model::Code; |
use Perly::Model::Code; |
14 |
use Perly::Model::Input; |
use Perly::Model::Input; |
15 |
|
use Data::UUID; |
16 |
|
|
17 |
=head2 arguments |
=head2 arguments |
18 |
|
|
54 |
$self->result->failure('You must upload something!'); |
$self->result->failure('You must upload something!'); |
55 |
return 1; |
return 1; |
56 |
} |
} |
57 |
my $outcome; |
|
58 |
my $content; |
my $content; |
59 |
|
my $filename; |
60 |
|
|
61 |
if ( my $fh = $self->argument_value('file') ) { |
if ( my $fh = $self->argument_value('file') ) { |
62 |
local $/; |
local $/; |
63 |
$content = <$fh>; |
$content = <$fh>; |
66 |
# doesn't try to save it away (and fail) when we do the redirect |
# doesn't try to save it away (and fail) when we do the redirect |
67 |
|
|
68 |
$self->argument_value( 'file', "" ); |
$self->argument_value( 'file', "" ); |
69 |
|
$filename = scalar( $fh ); |
70 |
} else { |
} else { |
71 |
$content = $self->argument_value('content'); |
$content = $self->argument_value('content'); |
72 |
|
my $uuid = Data::UUID->new(); |
73 |
|
$filename = $uuid->create_str; |
74 |
} |
} |
75 |
|
|
76 |
|
|
77 |
my $format = $self->argument_value( 'format' ); |
my $format = $self->argument_value( 'format' ); |
78 |
|
|
79 |
my $id; |
my $id; |
80 |
if ( $format eq 'input' ) { |
if ( $format eq 'input' ) { |
81 |
my $input = Perly::Model::Input->new(); |
my $input = Perly::Model::Input->new(); |
82 |
$id = $input->create( |
eval { |
83 |
content => $content |
$id = $input->create( |
84 |
); |
name => $filename, |
85 |
|
content => $content, |
86 |
|
); |
87 |
|
}; |
88 |
|
die "$@" if ($@); |
89 |
} else { |
} else { |
90 |
my $code = Perly::Model::Code->new(); |
my $code = Perly::Model::Code->new(); |
91 |
$id = $code->create( |
eval { |
92 |
source => $content |
$id = $code->create( |
93 |
); |
name => $filename, |
94 |
|
source => $content, |
95 |
|
); |
96 |
|
}; |
97 |
|
die "$@" if ($@); |
98 |
} |
} |
99 |
|
|
100 |
my $message = "Created $format $id " . length( $content ) . " bytes"; |
my $message = "Created $format width " . length( $content ) . " bytes [$id/$filename]"; |
101 |
|
|
102 |
# $self->result->content( $_ => $outcome->{$_} ) for keys %{$outcome}; |
# $self->result->content( $_ => $outcome->{$_} ) for keys %{$outcome}; |
103 |
$self->result->message($message); |
$self->result->message($message); |