Authen-Quiz

 view release on metacpan or  search on metacpan

lib/Authen/Quiz.pm  view on Meta::CPAN


=head2 question

The question displayed in the input form is set.

This method sets a unique HEX value in session_id at the same time.

  my $question= $q->question;

=head2 session_id

It is made to succeed by setting the value received by this method in the hidden field of
the input form.

When the check_answer method is called, this value is needed.

  my $question   = $q->question;
  my $session_id = $q->session_id;

=head2 check_answer ([SESSION_ID], [ANSWER_STRING])

It checks whether the answer input to the form is correct.

The value received by the session_id method is passed to SESSION_ID.

The input data is passed to ANSWER_STRING as it is.

* It is a caution needed because it doesn't do Validation.

  my $session_id = validate($cgi->param('quiz_session')) || return valid_error( ..... );
  my $answer     = validate($cgi->param('quiz_answer'))  || return valid_error( ..... );
  if ($q->check_answer($session_id, $answer)) {
  	# success.
  } else {
  	return valid_error( ..... );
  }

=head2 remove_session ([SESSION_ID])

The data of the quiz session is deleted.

When SESSION_ID is omitted, all data is deleted.

  $q->session_remove( $session_id );


=head1 OTHERS

There might be a problem in the response because it reads the quiz data every time.
If the Wrapper module is made and cash is used, this can be solved.

  package MyAPP::AuthQuizWrapper;
  use strict;
  use warnings;
  use Cache::Memcached;
  use base qw/ Authen::Quiz /;
  
  sub load_quiz {
     my $cache= Cache::Memcached->new;
     $cache->get('authen_quiz_data') || do {
         my $data= $_[0]->SUPER::load_quiz;
         $cache->set('authen_quiz_data'=> $data, 600);
         data;
       };
  }
  
  1;

Or, please use L<Authen::Quiz::Plugin::Memcached>.

=head1 SEE ALSO

L<Carp>,
L<Class::Accessor::First>,
L<Digest::SHA1>,
L<File::Spec>,
L<YAML::Syck>,
L<YAML>,

L<http://egg.bomcity.com/wiki?Authen%3a%3aQuiz>,

=head1 AUTHOR

Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2008 by Bee Flag, Corp. E<lt>http://egg.bomcity.com/E<gt>.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.

=cut



( run in 1.167 second using v1.01-cache-2.11-cpan-364913b4093 )