Skip to content

Commit

Permalink
added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
typester committed Nov 10, 2012
1 parent ca1ad29 commit f09a29c
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions lib/Sub/Rate/NoMaxRate.pm
Expand Up @@ -15,3 +15,97 @@ before generate => sub {
};

__PACKAGE__->meta->make_immutable;

__END__
=for stopwords SUBs sublist
=head1 NAME
Sub::Rate::NoMaxRate - auto calculate max_rate
=head1 SYNOPSIS
my $rate = Sub::Rate::NoMaxRate->new;
$rate->add( 10 => sub { ... } ); # sub1
$rate->add( 20 => sub { ... } ); # sub2
my $func = $rate->generate;
# Calling this $func then:
# sub1 will be called by rate about 10/30
# sub2 will be called by rate about 20/30
$func->();
=head1 DESCRIPTION
Sub::Rate::NoMaxRate is a subclass of L<Sub::Rate>.
This module has no C<max_rate> option and calculate it automatically.
=head1 CLASS METHODS
=head2 new(%options)
my $obj = Sub::Rate->new;
Create Sub::Rate object.
Available options are:
=over
=item * rand_func => 'CodeRef'
Random calculate function. Default is:
sub {
CORE::rand($_[0]);
};
You can change random function to your own implementation by this option.
C<max_rate> is passed as C<$_[0]> to this function.
=back
=head2 METHODS
=head2 add($rate : Number|Str, $sub :CodeRef)
$obj->add( 10, sub { ... } );
$obj->add( 20, sub { ... } );
$obj->add( 'default', sub { ... } );
Add C<$sub> to internal sublist rate by C<$rate>.
If C<$rate> is not number but "default", then C<$sub> is registered as default sub.
If default sub is already registered, it will be replaced.
=head2 generate()
my $sub = $obj->generate;
Create a new sub that dispatch functions by its rates.
=head2 clear()
$obj->clear;
Clear all registered functions and default function.
=head1 AUTHOR
Daisuke Murase <typester@cpan.org>
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2012 KAYAC Inc. All rights reserved.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=cut

0 comments on commit f09a29c

Please sign in to comment.