ASP4
view release on metacpan or search on metacpan
README.markdown view on Meta::CPAN
</select>
</p>
<p>
<label>Subject:</label>
<input type="text" name="subject" maxlength="100" />
</p>
<p>
<label>Message:</label><br/>
<textarea name="body"></textarea>
</p>
<p>
<input type="submit" value="Send Message" />
</p>
</form>
</div>
</asp:Content>
The form submits to `/handlers/app.send` which maps to `handlers/app/send.pm`
File: `handlers/app/send.pm`
package app::send;
use strict;
use warnings 'all';
use base 'ASP4::FormHandler';
use vars __PACKAGE__->VARS;
use App::db::user;
use App::db::message;
sub run {
my ($self, $context) = @_;
# Create the message:
my $msg = eval {
App::db::message->do_transaction(sub {
my $msg = App::db::message->create(
from_user_id => $Session->{user_id},
to_user_id => $Form->{to_user_id},
subject => $Form->{subject},
body => $Form->{body},
);
# Send an email to the recipient:
$Server->Mail(
from => 'root@localhost',
'reply-to' => $msg->sender->email,
to => $msg->recipient->email,
subject => 'New in-club message',
message => <<"MSG",
Dear user,
Another user (@{[ $msg->sender->email ]}) has sent you an in-club message.
Please login and view it on your profile at http://$ENV{HTTP_HOST}/
Yours,
The "In Club"
MSG
);
# Finally:
return $msg;
});
};
if( $@ ) {
$Session->{msg} = "Error: Your message could not be sent.";
$Session->save;
return $Response->Redirect( $ENV{HTTP_REFERER} );
}
else {
$Session->{msg} = "New message sent successfully.";
$Session->save;
return $Response->Redirect( $ENV{HTTP_REFERER} );
}
}
# BUGS
It's possible that some bugs have found their way into this release.
Use RT [http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4](http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4) to submit bug reports.
# HOMEPAGE
Please visit the ASP4 homepage at [http://0x31337.org/code/](http://0x31337.org/code/) to see examples
of ASP4 in action.
# AUTHOR
John Drago <jdrago_999@yahoo.com>
# COPYRIGHT
This software is Free software and may be used and redistributed under the same
terms as perl itself.
( run in 1.156 second using v1.01-cache-2.11-cpan-39bf76dae61 )