App-calendr
view release on metacpan or search on metacpan
- Moved author test scripts to xt/ subfolder.
0.24 Sun Mar 31 11:40:00 2019
- Used namespace::autoclean instead.
0.23 Thu Sep 28 12:20:00 2017
- Downgraded min version requirement for Calendar::Julian.
- Upgraded min version requirement for Calendar::Bahai in the test script t/app-calendr.t
0.22 Wed Sep 27 10:50:00 2017
- Proposed fix for issue RT #123094 (added min version requirement for installed calendars).
0.21 Thu Aug 24 12:00:00 2017
- Added order to command line options.
0.20 Sun Aug 06 04:35:00 2017
- Renamed option '--gregorian' to '--gdate', just to make sure
it doesn't confuse user with the calendar name 'Gregorian'.
0.19 Tue Aug 01 11:35:00 2017
- Tidied up test scripts and removed "-T" switch.
0.18 Sat Jul 29 08:40:00 2017
- Renamed option '--julian' to '--jday', just to make sure
it doesn't confuse user with the calendar name 'Julian'.
0.17 Sun Jul 23 10:50:00 2017
- Added support for Julian Calendar.
0.16 Sun Jul 23 03:20:00 2017
- Added support for Hebrew Calendar.
0.15 Sat Apr 08 18:50:00 2017
- Updated copyright year information in the pod document.
0.12 Thu Jun 16 12:30:00 2016
- Added command line parameter "--list_month_names".
0.11 Sat Jun 11 01:30:00 2016
- Updated "SYNOPSIS" with respect to the changes to the parameter --month.
0.10 Wed Jun 08 10:25:00 2016
- Added support for month name in addition to month number. Now --month flag can be set as month name.
0.09 Sun May 08 02:30:00 2016
- Added ability to generate calendar in SVG format.
0.08 Sat Mar 19 06:10:00 2016
- Added support for Gregorian Calendar.
- Updated copyright year information in the pod document.
0.07 Wed Jan 06 10:10:00 2016
- Fixed 'provides' list in the Makefile.PL script.
- Added $AUTHORITY to the distribution.
0.06 Sun Nov 22 10:15:00 2015
lib/App/calendr.pm view on Meta::CPAN
It provides simple command line interface to the package L<App::calendr>. The
distribution contains a script C<calendr>, using package L<App::calendr>.
=head1 SYNOPSIS
You can list all command line options by giving C<--help> flag.The C<--name> flag
is only mandatory. Rest of all are optionals. If C<--month> flag is passed then
the C<--year> flag becomes mandatory and vice versa. In case neither of them is
passed in then it would look for C<--gdate>/C<--jday> flag and accordingly act on
it. In case none C<flag> passed in it would show the current calendar month.
$ calendr --help
USAGE: calendr [-h] [long options...]
--name: String
Calendar name e.g. Bahai,Gregorian,Hebrew,Hijri,Julian,Persian,Saka.
Default is Gregorian.
--month: String
lib/App/calendr.pm view on Meta::CPAN
--year: Int
Year number (3/4 digits)
--gdate: String
Gregorian date (YYYY-MM-DD)
--jday: Int
Julian day
--as_svg:
Generate calendar in SVG format
--list_month_names:
List calendar month names
--usage:
show a short help message
-h:
show a compact help message
--help:
show a long help message
--man:
show the manual
=head1 SUPPORTED CALENDARS
The following supported calendars can be installed individually.
=over 4
=item * L<Calendar::Bahai>
=item * L<Calendar::Gregorian>
=item * L<Calendar::Hebrew>
=item * L<Calendar::Hijri>
lib/App/calendr.pm view on Meta::CPAN
$ cpanm Task::Calendar
=cut
sub BUILD {
my ($self) = @_;
my $plugins = [ plugins ];
foreach my $plugin (@$plugins) {
my $cal = _load_calendar($plugin);
if (defined $cal) {
my $inst_ver = ${plugin}->VERSION;
my $min_ver = $cal->{min_ver};
my $cal_name = $cal->{name};
if ($inst_ver >= $min_ver) {
$self->{calendars}->{$cal_name} = $plugin->new;
}
else {
$FAILED_CALENDARS->{$cal_name} = {
cal_name => $cal_name,
min_ver => $min_ver,
inst_ver => $inst_ver,
};
}
}
}
lib/App/calendr.pm view on Meta::CPAN
=cut
sub run {
my ($self) = @_;
my $month = $self->month;
my $year = $self->year;
my $name = $self->name || $DEFAULT_CALENDAR;
my $supported_calendars = _supported_calendars();
my $supported_cal = $supported_calendars->{uc($name)};
die "ERROR: Unsupported calendar [$name] received.\n" unless defined $supported_cal;
my $calendar = $self->get_calendar($name);
# Is supported calendar installed?
if (!defined $calendar) {
# Is the calendar failed version pass min ver?
if (exists $FAILED_CALENDARS->{$supported_cal->{name}}) {
my $min_ver = $FAILED_CALENDARS->{$supported_cal->{name}}->{min_ver};
my $inst_ver = $FAILED_CALENDARS->{$supported_cal->{name}}->{inst_ver};
my $cal_name = $FAILED_CALENDARS->{$supported_cal->{name}}->{cal_name};
die sprintf("ERROR: Found %s v%s but required v%s.\n", $cal_name, $inst_ver, $min_ver);
}
die "ERROR: Calendar [$name] is not installed.\n";
}
if (defined $month || defined $year) {
if (defined $month) {
die "ERROR: Missing year.\n" unless defined $year;
}
else {
die "ERROR: Missing month.\n" if defined $year;
}
if (defined $month) {
if (ref($calendar) eq 'Calendar::Hebrew') {
$calendar->date->validate_hebrew_month($month, $year);
}
else {
$calendar->date->validate_month($month, $year);
}
if ($month =~ /^[A-Z]+$/i) {
$month = $calendar->date->get_month_number($month);
}
$calendar->month($month);
}
if (defined $year) {
$calendar->date->validate_year($year);
$calendar->year($year);
}
}
elsif (defined $self->gdate) {
my $gdate = $self->gdate;
die "ERROR: Invalid gregorian date '$gdate'.\n"
unless ($gdate =~ /^\d{4}\-\d{2}\-\d{2}$/);
my ($year, $month, $day) = split /\-/, $gdate, 3;
print $calendar->from_gregorian($year, $month, $day) and return;
}
elsif (defined $self->jday) {
my $julian_day = $self->jday;
die "ERROR: Invalid julian day '$julian_day'.\n"
unless ($julian_day =~ /^\d+\.?\d?$/);
print $calendar->from_julian($julian_day) and return;
}
elsif (defined $self->list_month_names) {
my $month_names = $calendar->date->months;
shift @$month_names; # Remove empty entry.
print join("\n", @$month_names), "\n" and return;
}
if (defined $self->as_svg) {
print $calendar->as_svg, "\n";
}
else {
print $calendar, "\n";
}
}
sub get_calendar {
my ($self, $name) = @_;
return unless defined $name;
my $supported_cals = _supported_calendars();
my $cal_pkg = $supported_cals->{uc($name)}->{name};
return $self->{calendars}->{$cal_pkg} if exists $self->{calendars}->{$cal_pkg};
return;
}
#
#
# PRIVATE METHODS
sub _load_calendar {
my ($plugin) = @_;
return unless defined $plugin;
my $calendars = _supported_calendars();
foreach my $key (keys %$calendars) {
return $calendars->{$key} if ($calendars->{$key}->{name} eq $plugin);
}
return;
}
sub _supported_calendars {
return {
'BAHAI' => { name => 'Calendar::Bahai', min_ver => 0.46 },
'GREGORIAN' => { name => 'Calendar::Gregorian', min_ver => 0.15 },
'HEBREW' => { name => 'Calendar::Hebrew', min_ver => 0.03 },
'HIJRI' => { name => 'Calendar::Hijri', min_ver => 0.33 },
'JULIAN' => { name => 'Calendar::Julian', min_ver => 0.01 },
'PERSIAN' => { name => 'Calendar::Persian', min_ver => 0.35 },
'SAKA' => { name => 'Calendar::Saka', min_ver => 1.34 },
};
lib/App/calendr/Option.pm view on Meta::CPAN
use 5.006;
use Data::Dumper;
use Moo::Role;
use namespace::autoclean;
use Types::Standard -all;
use MooX::Options;
has calendars => (is => 'rw');
option name => (is => 'ro', order => 1, isa => Str, format => 's', doc => "Calendar name e.g. Bahai,Gregorian,Hebrew,Hijri,Julian,Persian,Saka.\n\tDefault is Gregorian.");
option month => (is => 'ro', order => 2, isa => Str, format => 's', doc => 'Month number/name e.g. 1,2,3... or January,February...');
option year => (is => 'ro', order => 3, isa => Int, format => 'i', doc => 'Year number (3/4 digits)');
option gdate => (is => 'ro', order => 4, isa => Str, format => 's', doc => 'Gregorian date (YYYY-MM-DD)');
option jday => (is => 'ro', order => 5, isa => Str, format => 'i', doc => 'Julian day');
option as_svg => (is => 'ro', order => 6, doc => 'Generate calendar in SVG format');
option list_month_names => (is => 'ro', order => 7, doc => 'List calendar month names');
=head1 DESCRIPTION
B<FOR INTERNAL USE ONLY>
=head1 AUTHOR
Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
=head1 REPOSITORY
t/app-calendr.t view on Meta::CPAN
use Test::More;
my $min_ver = 0.46;
eval "use Calendar::Bahai $min_ver";
plan skip_all => "Calendar::Bahai $min_ver required" if $@;
#eval { App::calendr->new->run };
#like($@, qr/Missing required arguments: name/);
eval { App::calendr->new({ name => 'xxx' })->run };
like($@, qr/Unsupported calendar/);
eval { App::calendr->new({ name => 'bahai', month => 'x', year => 172 })->run };
like($@, qr/Invalid month name/);
eval { App::calendr->new({ name => 'bahai', month => -1, year => 172 })->run };
like($@, qr/Invalid month/);
eval { App::calendr->new({ name => 'bahai', month => 0, year => 172 })->run };
like($@, qr/Invalid month/);
( run in 2.682 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )