NAME
Project::Euler::Problem::Base - Abstract class that the problems will extend from
VERSION
Version v0.2.1
SYNOPSIS
use Moose;
with Project::Euler::Problem::Base;
DESCRIPTION
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.
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 ( ProblemName ) # 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 ( ProblemLink ) # 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 may not have use for input
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
ABSTRACT FUNCTIONS
These two functions must also be overridden by the extending class
_check_input
Ensure the input provided by the user is compliant
_solve_problem
This the main function which will return the status/answer for a problem
PROVIDED FUNCTIONS
solve
This function will point to the internal function that actually solves 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 in scalar context, or an array containing the status, calculated answer, and expected answer.
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 => (1);
my $custom_answer = $problem_1->solve;
my ($status, $answer, $expected) = $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.
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.