script/cal.pl untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 91 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2  
3 use strict;
4 use warnings;
5 use Pod::Usage;
6 use Getopt::Long qw(:config auto_help);
7 use Calendar::Any::Util::Calendar qw(:all);
8 use I18N::Langinfo;
9  
10 my %Config = (
11 'locale' => langinfo(I18N::Langinfo::CODESET()),
12 'weekstart' => 0,
13 'type' => 'gregorian',
14 );
15  
16 my ($month, $year, $type, $china, $gregorian, $julian);
17  
18 # Install configuration
19 $week_start_day = $Config{weekstart};
20 $type = $Config{type};
21  
22 GetOptions(
23 'locale=s' => \$Config{locale},
24 'china' => \$china,
25 'gregorian' => \$gregorian,
26 'julian' => \$julian,
27 'type=s' => \$type,
28 'weekstart=i' => \$week_start_day,
29 );
30  
31 # Check month and year
32 my @time = localtime;
33 $month = shift || $time[4]+1;
34 $year = shift || $time[5]+1900;
35 unless ( $month && $year && $month>0 && $month<13 ) {
36 pod2usage();
37 }
38  
39 # Check package
40 if ( $china) {
41 $type = "China";
42 } elsif ( $gregorian ) {
43 $type = "Gregorian";
44 } elsif ( $julian ) {
45 $type = "Julian";
46 }
47 $type = ucfirst($type);
48  
49 ## ensure the package is implement
50 unless ( defined($type) && grep { $type eq $_ } qw(China Gregorian Julian) ) {
51 pod2usage();
52 }
53  
54 my $cal = Calendar::Any::Util::Calendar::calendar($month, $year, $type)."\n";
55 if ( $type =~ /China/ ) {
56 # out put using locale
57 require Encode;
58 Encode::_utf8_on($cal);
59 print Encode::encode($Config{locale}, $cal);
60 } else {
61 print $cal;
62 }
63  
64 __END__