App-Greple-ical
view release on metacpan or search on metacpan
lib/App/Greple/ical.pm view on Meta::CPAN
our $VERSION = '0.02';
use v5.14;
use warnings;
use Carp;
use Exporter 'import';
our @EXPORT = qw(&print_simple &print_detail &print_desc);
sub print_detail {
$_ = &print_simple . &print_desc . "\n";
s/\n(?=.)/\r/sg;
$_;
}
sub print_simple {
s/\r//g;
my $s = '';
my(@s, @e);
if (@s = /^DTSTART.*(\d{4})(\d\d)(\d\d)(?:T(\d\d)(\d\d))?/m) {
$s .= "$1/$2/$3";
$s .= " $4:$5" if defined $4;
}
if (@e = /^DTEND.*(\d{4})(\d\d)(\d\d)(?:T(\d\d)(\d\d))?/m) {
if ($s[0]eq$e[0] and $s[1]eq$e[1] and $s[2]+1>=$e[2]) {
$s .= "-$4:$5" if defined $4;
} else {
$s .= "-";
$s .= "$1/" if $s[0] ne $e[0];
$s .= "$2/$3";
}
}
$s .= " ";
/^SUMMARY:(.*)/m and $s .= $1;
/^DESCRIPTION:/m and $s .= "*";
/^LOCATION:(.*)/m and $s .= " \@[$1]";
$s .= "\n";
$s;
}
sub print_desc {
my $desc = '';
if (/^(DESCRIPTION.*\n(?:\s.*\n)*)/m) {
$desc = $1;
for ($desc) {
s/\n\s+//g;
s/\\n/\n/g;
s/\\\\t/\t/g;
s/\\,/,/g;
}
}
$desc;
}
1;
__DATA__
option default \
--chdir=~/Library/Calendars/*.caldav/*.calendar/Events \
--glob=*.ics
option --simple \
--all --print print_simple
option --detail \
--all --print print_detail --pf 'sort | tr \\015 \\012'
( run in 0.639 second using v1.01-cache-2.11-cpan-5735350b133 )