/[Perly]/lib/Perly/Action/Upload.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/Perly/Action/Upload.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations)
Tue Jun 5 14:21:22 2007 UTC (17 years ago) by dpavlin
File size: 2200 byte(s)
added filenames, from upload name (if available) or from UUID
1 dpavlin 8 use warnings;
2     use strict;
3    
4     =head1 NAME
5    
6     Perly::Action::Upload
7    
8     =cut
9    
10     package Perly::Action::Upload;
11     use base qw/Perly::Action::CreateCode Jifty::Action/;
12    
13     use Perly::Model::Code;
14 dpavlin 9 use Perly::Model::Input;
15 dpavlin 12 use Data::UUID;
16 dpavlin 8
17     =head2 arguments
18    
19     The fields for C<Upload> are:
20    
21     =over 4
22    
23     =item file: The uploaded file
24    
25     =back
26    
27     =cut
28    
29     sub arguments {
30     {
31     content => { label => 'The text version', render_as => 'Textarea' },
32     file => {
33     label => '',
34     render_as => 'Upload',
35     },
36     format => {
37     label => 'Textfile format',
38 dpavlin 9 valid_values => [qw(input perl)],
39     default_value => 'auto',
40     render_as => 'select',
41 dpavlin 8 }
42     }
43     }
44    
45     =head2 take_action
46    
47     Import the textfile dump
48    
49     =cut
50    
51     sub take_action {
52     my $self = shift;
53     unless( $self->argument_value('file') || $self->argument_value('content') ) {
54     $self->result->failure('You must upload something!');
55     return 1;
56     }
57 dpavlin 12
58 dpavlin 8 my $content;
59 dpavlin 12 my $filename;
60    
61 dpavlin 8 if ( my $fh = $self->argument_value('file') ) {
62     local $/;
63     $content = <$fh>;
64    
65     # This kills the filehandle from the action, so Apache::Session
66     # doesn't try to save it away (and fail) when we do the redirect
67    
68     $self->argument_value( 'file', "" );
69 dpavlin 12 $filename = scalar( $fh );
70 dpavlin 8 } else {
71     $content = $self->argument_value('content');
72 dpavlin 12 my $uuid = Data::UUID->new();
73     $filename = $uuid->create_str;
74 dpavlin 8 }
75    
76 dpavlin 12
77 dpavlin 9 my $format = $self->argument_value( 'format' );
78 dpavlin 8
79 dpavlin 9 my $id;
80     if ( $format eq 'input' ) {
81     my $input = Perly::Model::Input->new();
82 dpavlin 12 eval {
83     $id = $input->create(
84     name => $filename,
85     content => $content,
86     );
87     };
88     die "$@" if ($@);
89 dpavlin 9 } else {
90     my $code = Perly::Model::Code->new();
91 dpavlin 12 eval {
92     $id = $code->create(
93     name => $filename,
94     source => $content,
95     );
96     };
97     die "$@" if ($@);
98 dpavlin 9 }
99 dpavlin 8
100 dpavlin 12 my $message = "Created $format width " . length( $content ) . " bytes [$id/$filename]";
101 dpavlin 9
102 dpavlin 8 # $self->result->content( $_ => $outcome->{$_} ) for keys %{$outcome};
103     $self->result->message($message);
104     warn "## $message";
105     delete Jifty->handler->stash->{RECORD_ARGUMENTS};
106     }
107    
108     1;

  ViewVC Help
Powered by ViewVC 1.1.26