Acme-PM-Paris-Meetings

 view release on metacpan or  search on metacpan

lib/Acme/PM/Paris/Meetings.pm  view on Meta::CPAN

package Acme::PM::Paris::Meetings;

use warnings;
use strict;

use DateTime::Format::ICal;

use Exporter 'import';
our @EXPORT = qw(next_meeting);

=head1 NAME

Acme::PM::Paris::Meetings - Get the date/time of the next Paris.pm meeting!

=head1 VERSION

Version 200905.04

=cut

our $VERSION = '200905.04';


=head1 SYNOPSIS

Using the 'paris-pm' script:

    $ paris-pm -3


One-liner:

    perl -MAcme::PM::Paris::Meetings -e "print next_meeting"

Longer:

    use DateTime;
    use Acme::PM::Paris::Meetings;

    my $rec = Acme::PM::Paris::Meetings::recurrence();
    my $dt = $rec->iterator->next(DateTime->now(time_zone => 'Europe/Paris'));
    ...

=cut



=head1 FUNCTIONS


=head2 recurrence

Returns a new DateTime::Set from which you can get the date/time of the planned
Paris.pm meeting for the following months.

=cut

sub recurrence
{
    my $dtstart = @_
                ? $_[0]
                : DateTime->now(time_zone => 'Europe/Paris',
                                locale => 'fr_FR')
                                ->truncate(to => 'day');
    DateTime::Format::ICal->parse_recurrence(
        recurrence => ical(),
        dtstart => $dtstart,
    );
}

=head2 next_meeting

Convenience function that returns the date/time of the next Paris.pm meeting
as a string formatted for french humans.

An internal recurrence object is maintained so if you call the method multiple times,
you will get different results.

=cut

my $iterator;

sub next_meeting
{
    my $count = shift(@_) || -1;

    unless (defined $iterator) {
        $iterator = recurrence()->iterator;
    }

    if (wantarray && $count >= 1) {
        map { $iterator->next()->strftime("%A %d/%m/%Y %Hh%M") } 1..$count;
    } else {
        $iterator->next()->strftime("%A %d/%m/%Y %Hh%M")
    }
}


=head2 ical

Returns the current ICal expression for the next Paris.pm meeting.

=cut

sub ical {
	'FREQ=MONTHLY;BYDAY=2WE;BYHOUR=20;BYMINUTE=0;BYSECOND=0'
}


1; # End of Acme::PM::Paris::Meetings
__END__

=head1 VERSION NUMBERS

Numbering scheme: C<YYYYMM.nn> where C<YYYY> is the year, C<MM> the month and
C<nn> the release number in the month.

=head1 AUTHOR

Olivier MenguE<eacute>, C<< <dolmen at cpan.org> >>

=head1 BUGS

Let's hope a recent release of the module has been released and you are using it!



( run in 2.173 seconds using v1.01-cache-2.11-cpan-302cb4679cc )