Permalink
Browse files

Version 0.1

  • Loading branch information...
1 parent 5a7b191 commit f3b31f7f4777bd5af4fc554ac73eebd992c7d353 Thomas Fahle committed Aug 19, 2010
View
@@ -0,0 +1 @@
+logs/*
View
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'RandomNumber',
+ AUTHOR => q{YOUR NAME <youremail@example.com>},
+ VERSION_FROM => 'lib/RandomNumber.pm',
+ ABSTRACT => 'YOUR APPLICATION ABSTRACT',
+ ( $ExtUtils::MakeMaker::VERSION >= 6.3002
+ ? ( 'LICENSE' => 'perl' )
+ : () ),
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'YAML' => 0,
+ 'Dancer' => 1.1805,
+ 'Math::Random' => 0,
+ 'Template' => 0,
+ 'Data::FormValidator' => 0,
+ 'Regexp::Common' => 0,
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'RandomNumber-*' },
+);
View
7 README
@@ -24,4 +24,11 @@ and point your favourite browser to 0.0.0.0:3000.
Enjoy!
+If anything fails run the tests
+
+prove -l -v t/*
+
+or have a look at the log folder.
+
+
View
@@ -0,0 +1,4 @@
+#!/usr/bin/perl
+use Dancer;
+load_app 'RandomNumber';
+dance;
View
@@ -0,0 +1,13 @@
+# PSGI application bootstraper for Dancer
+use Dancer;
+load_app 'RandomNumber';
+
+use Dancer::Config 'setting';
+setting apphandler => 'PSGI';
+Dancer::Config->load;
+
+my $handler = sub {
+ my $env = shift;
+ my $request = Dancer::Request->new($env);
+ Dancer->dance($request);
+};
View
@@ -0,0 +1,5 @@
+layout: "main"
+logger: "file"
+enviroment: "development"
+template: "template_toolkit"
+
@@ -0,0 +1,5 @@
+log: "debug"
+warnings: 1
+show_errors: 1
+auto_reload: 0
+
@@ -0,0 +1,6 @@
+log: "warning"
+warnings: 0
+show_errors: 0
+route_cache: 1
+auto_reload: 0
+
View
@@ -0,0 +1,106 @@
+package RandomNumber;
+use Dancer ':syntax';
+use RandomNumber::Generator qw/random_number/;
+use RandomNumber::Validator qw/validate_low_high/;
+our $VERSION = '0.1';
+
+=head1 NAME RandomNumber - Dancer WebApp
+
+
+=head1 SYNOPSIS
+
+
+ use RandomNumber::Validator qw/validate_low_high/;
+
+=cut
+
+=head1 SUBROUTINES
+
+Our subroutines are route handlers.
+
+=cut
+
+=head2 get /
+
+handles get requests to the frontpage (/)
+
+=cut
+
+
+get '/' => sub {
+ template 'index';
+};
+
+=head2 post /
+
+handles post requests to the frontpage (/)
+
+=cut
+
+post '/' => sub {
+ my $high = params->{high};
+ my $low = params->{low};
+
+ my $results = validate_low_high( { low => $low , high => $high } );
+
+ my $missing_low = not defined( $results->valid('low') );
+ my $missing_high = not defined( $results->valid('high') );
+
+ my $random = undef;
+
+ if ( $results->success() ) {
+ $random = random_number( $low, $high );
+ }
+
+ template 'index',
+ {
+ random => $random,
+ low => $low,
+ high => $high,
+ missing_low => $missing_low,
+ missing_high => $missing_high,
+ };
+};
+
+true;
+
+__END__
+=head1 DEPENDENCIES
+
+=over 4
+
+=item Dancer
+
+=item Template
+
+=item Math::Random
+
+=item Regexp::Common
+
+=item Data::FormValidator
+
+=back
+
+=head1 BUGS AND LIMITATIONS
+
+Please report problems to Thomas Fahle (cpan at thomas-fahle.de)
+
+Patches are welcome.
+
+=head1 AUTHOR
+
+Thomas Fahle (cpan at thomas-fahle.de)
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c) 2010 Thomas Fahle (cpan at thomas-fahle.de)
+All rights reserved.
+
+
+This module is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself. See L<perlartistic>. This program is
+distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE.
+
+=cut
@@ -0,0 +1,118 @@
+package RandomNumber::Generator;
+
+use warnings;
+use strict;
+
+use Math::Random qw/:all/;
+
+# Dancer Logging
+use Dancer ':syntax';
+
+use Exporter;
+
+our $VERSION = '0.01';
+our @ISA = qw/Exporter/;
+our @EXPORT = ();
+our @EXPORT_OK = qw/ random_number/;
+
+=head1 NAME RandomNumber::Generator - Generates Random Numbers
+
+
+=head1 SYNOPSIS
+
+
+ use RandomNumber::Generator qw/random_number/;
+
+=cut
+
+=head1 SUBROUTINES
+
+=cut
+
+=head2 random_number( $min , $max);
+
+
+Returns a random number in the range $min .. $max or a String
+with an Error-Message if out of range (2147483561).
+
+ my $min = -100;
+ my $max = 500;
+ my $random_number = random_number($min,$max);
+
+Throws warnings and errors from Math::Random.
+
+=cut
+
+sub random_number {
+ my $low = shift @_;
+ my $high = shift @_;
+
+ {
+ no warnings;
+ debug "Low: '$low'";
+ debug "High: '$high'";
+ }
+
+ if ( $low > $high ) {
+
+ # Swap values
+ ( $low, $high ) = ( $high, $low );
+ debug "Swapping High and Low";
+ debug "New Low: '$low'";
+ debug "New High: '$high'";
+ }
+
+ if ( $high - $low > 2147483561 ) {
+ warning "Out of range '$low':'$high'";
+
+ # Return a String
+ return "Fehler: Bereich zu gross (max 2147483561)";
+ }
+
+# When called in an array context, returns an array of $n integer deviates generated
+# from a uniform($low, $high) distribution on the integers. When called in a scalar context,
+# generates and returns only one such deviate as a scalar, regardless of the value of $n.
+ my $n = 1;
+ my $random_number = random_uniform_integer( $n, $low, $high );
+ debug "Random_Number: <$random_number>";
+ return $random_number;
+}
+
+1;
+
+=head1 DEPENDENCIES
+
+=over 4
+
+=item Exporter
+
+=item Math::Random
+
+=item Dancer
+
+=back
+
+=head1 BUGS AND LIMITATIONS
+
+Please report problems to Thomas Fahle (cpan at thomas-fahle.de)
+
+Patches are welcome.
+
+=head1 AUTHOR
+
+Thomas Fahle (cpan at thomas-fahle.de)
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c) 2010 Thomas Fahle (cpan at thomas-fahle.de)
+All rights reserved.
+
+
+This module is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself. See L<perlartistic>. This program is
+distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE.
+
+=cut
+
Oops, something went wrong.

0 comments on commit f3b31f7

Please sign in to comment.