NAME
Perl::Achievements::Achievement - base role for achievements
VERSION
version 0.4.0
SYNOPSIS
package Perl::Achievements::Achievement::PerlAchiever;
use strict;
use warnings;
use Moose;
use MooseX::SemiAffordanceAccessor;
with 'Perl::Achievements::Achievement';
has runs => (
traits => [ qw/ Counter Perl::Achievements::Role::ConfigItem / ],
isa => 'Num',
is => 'rw',
default => 0,
handles => {
inc_runs => 'inc',
},
);
sub scan {
my $self = shift;
$self->inc_runs;
return unless $self->runs >= 2** $self->level;
$self->inc_level;
$self->unlock(
sprintf "ran perl-achievements against %d scripts/modules",
2 ** ( $self->level - 1 )
);
}
1;
DESCRIPTION
Each type of achievement is a module consuming the Perl::Achievements::Achievement role.
To be able to preserve counters and states across runs, all attributes of the class having the Perl::Achievements::Role::ConfigItem trait will be serialized and saved in a yaml file in the $PERL_ACHIEVEMENTS_HOME/achievements
directory.
REQUIRED METHODS
scan()
scan
is the only required method by the role. It is typically invoked by the main scan()
method of the main Perl::Achievements object, and is expected to inspect the current Perl file (available via ppi()
) and unlock the achievement when the right conditions are met.
METHODS
app()
Returns the Perl::Achievements object to which this achievement object belongs to.
ppi()
Returns the PPI::Document object corresponding to the Perl script currently under study.
log( $message )
Logs the $message.
log_debug( $message )
Debug-level logging.
level()
Returns the current achieved level. A level of undef means that the achievement has not been reached yet, whereas a level of 0 is used for achievements that don't have multiple levels.
set_level( $level )
Sets the level to $level.
inc_level( $increment )
Increments the level by the $increment. If the increment is not given, increment by 1.
unlock( $details )
Unlocks the achievement. An optional message can be passed, providing specific on the deed.
If not set manually beforehand, unlocking the achievement would automatically set the level to 0.
AUTHOR
Yanick Champoux <yanick@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.