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

  ViewVC Help
Powered by ViewVC 1.1.26