File: Mock.pm

package info (click to toggle)
libcatmandu-perl 1.2024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,552 kB
  • sloc: perl: 17,037; makefile: 24; sh: 1
file content (61 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package Catmandu::IdGenerator::Mock;

use Catmandu::Sane;

our $VERSION = '1.2024';

use Moo;
use Catmandu::Util qw(check_natural);
use namespace::clean;

with 'Catmandu::IdGenerator';

has first_id =>
    (is => 'ro', isa => sub {check_natural($_[0])}, default => sub {0},);

has next_id =>
    (is => 'rwp', init_arg => undef, lazy => 1, builder => 'first_id',);

sub generate {
    my ($self) = @_;
    my $id = $self->next_id;
    $self->_set_next_id($id + 1);
    $id;
}

1;

__END__

=pod

=head1 NAME

Catmandu::IdGenerator::Mock - Generator of increasing identifiers

=head1 SYNOPSIS

    use Catmandu::IdGenerator::Mock;

    my $x = Catmandu::IdGenerator::Mock->new(first_id => 10);

    for (1..100) {
       printf "id: %s\n" m $x->generate;
    }

=head1 SEE ALSO

This L<Catmandu::IdGenerator> generates identifiers based on the sequence of
natural numbers.

=head1 CONFIGURATION

=over

=item first_id

First number to start from. Set to C<0> by default (zero-based numbering).

=back

=cut