NAME
Project::Euler::Problem::Base - Abstract class that the problems will extend from
VERSION
Version v0.2.0
SYNOPSIS
To ensure that each problem class performs a minimum set of functions, this class will define the basic subroutines and variables that every object must implement. This will make wrapping a gui around them much simpler in the future while also eliminating a lot of confustion that could arise from having different method names/conventions
with Project::Euler::Problem::Base;
SUBTYPES
Create the subtypes that we will use to validate the arguments defined by the extending classes
Base::link = $link =~ m_ \A \Qhttp://projecteuler.net/index.php?section=problems&id=\E \d+ \z _xms
Base::prob_name = str && 10 < len < 80
We also tell Moose how to coerce a given string into a DateTime object
VARIABLES
These are the base variables that every module should have. Because each extending module will be changing these values, we will force them to create functions which will set the attributes. We also declare the init_arg as undef so nobody creating an instance of the problem can over-write the values.
problem_number ( PosInt ) # Problem number on projecteuler.net
problem_name ( prob_name ) # Short name given by the module author
problem_date ( MyDateTime ) # Date posted on projecteuler.net
problem_desc ( str ) # Description posted on projecteuler.net
problem_link ( URL ) # URL to the problem's homepage
default_input ( str ) # Default input posted on projecteuler.net
default_answer ( str ) # Default answer to the default input
has_input ( boolean ) # Some problems might not have so this lets us disable it
use_defaults ( boolean ) # Use the default inputs
custom_input ( str ) # User provided input to the problem
custom_answer ( str ) # User provided answer to the problem
solve_status ( boolean ) # True means it was valid
solve_answer ( str ) # Last answer provided
FUNCTIONS
_check_input
_solve_problem
PROVIDED FUNCTIONS
solve
This is the function that should be called to solve the problem. Depending on the object attributes that are set, it uses either the default or provided inputs if they are required and returns the answer as a string
my $problem_1 = Project::Euler::Problem::P001->new();
my $def_answer = $problem_1->solve;
$problem_1->custom_input => (42);
$problem_1->custom_answer => (42);
$problem_1->use_defaults => (21);
my $custom_answer = $problem_1->solve;
status
This function simply returns a nice, readable status message that tells you the outcome of the last run of the module. This is way the array won't have to be parsed every time to determine the various states that are saved.
my $problem_1 = Project::Euler::Problem::P001->new();
$problem_1->solve;
my $message = $problem_1->last_run_message;
AUTHOR
Adam Lesperance, <lespea at cpan.org>
BUGS
Please report any bugs or feature requests to bug-project-euler at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Project-Euler. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Project::Euler::Base
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009 Adam Lesperance.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.