1Set::Infinite::_recurreUnsceer(3C)ontributed Perl DocumeSnetta:t:iIonnfinite::_recurrence(3)
2
3
4
6 Set::Infinite::_recurrence - Extends Set::Infinite with recurrence
7 functions
8
10 $recurrence = $base_set->_recurrence ( \&next, \&previous );
11
13 This is an internal class used by the DateTime::Set module. The API is
14 subject to change.
15
16 It provides all functionality provided by Set::Infinite, plus the abil‐
17 ity to define recurrences with arbitrary objects, such as dates.
18
20 * _recurrence ( \&next, \&previous )
21 Creates a recurrence set. The set is defined inside a 'base set'.
22
23 $recurrence = $base_set->_recurrence ( \&next, \&previous );
24
25 The recurrence functions take one argument, and return the 'next'
26 or the 'previous' occurence.
27
28 Example: defines the set of all 'integer numbers':
29
30 use strict;
31
32 use Set::Infinite::_recurrence;
33 use POSIX qw(floor);
34
35 # define the recurrence span
36 my $forever = Set::Infinite::_recurrence->new(
37 Set::Infinite::_recurrence::NEG_INFINITY,
38 Set::Infinite::_recurrence::INFINITY
39 );
40
41 my $recurrence = $forever->_recurrence(
42 sub { # next
43 floor( $_[0] + 1 )
44 },
45 sub { # previous
46 my $tmp = floor( $_[0] );
47 $tmp < $_[0] ? $tmp : $_[0] - 1
48 },
49 );
50
51 print "sample recurrence ",
52 $recurrence->intersection( -5, 5 ), "\n";
53 # sample recurrence -5,-4,-3,-2,-1,0,1,2,3,4,5
54
55 {
56 my $x = 234.567;
57 print "next occurence after $x = ",
58 $recurrence->{param}[0]->( $x ), "\n"; # 235
59 print "previous occurence before $x = ",
60 $recurrence->{param}[2]->( $x ), "\n"; # 234
61 }
62
63 {
64 my $x = 234;
65 print "next occurence after $x = ",
66 $recurrence->{param}[0]->( $x ), "\n"; # 235
67 print "previous occurence before $x = ",
68 $recurrence->{param}[2]->( $x ), "\n"; # 233
69 }
70
71 * is_forever
72 Returns true if the set is a single span, ranging from -Infinity to
73 Infinity.
74
75 * _is_recurrence
76 Returns true if the set is an unbounded recurrence, ranging from
77 -Infinity to Infinity.
78
80 * INFINITY
81 The "Infinity" value.
82
83 * NEG_INFINITY
84 The "-Infinity" value.
85
87 Support is offered through the "datetime@perl.org" mailing list.
88
89 Please report bugs using rt.cpan.org
90
92 Flavio Soibelmann Glock <fglock@pucrs.br>
93
94 The recurrence generation algorithm is based on an idea from Dave Rol‐
95 sky.
96
98 Copyright (c) 2003 Flavio Soibelmann Glock. All rights reserved. This
99 program is free software; you can distribute it and/or modify it under
100 the same terms as Perl itself.
101
102 The full text of the license can be found in the LICENSE file included
103 with this module.
104
106 Set::Infinite
107
108 DateTime::Set
109
110 For details on the Perl DateTime Suite project please see <http://date‐
111 time.perl.org>.
112
113
114
115perl v5.8.8 2007-04-17 Set::Infinite::_recurrence(3)