File Coverage

blib/lib/Date/Extract/ID.pm
Criterion Covered Total %
statement 23 26 88.4
branch 4 8 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 2 2 100.0
total 35 44 79.5


line stmt bran cond sub pod time code
1             package Date::Extract::ID;
2              
3             our $DATE = '2016-04-06'; # DATE
4             our $VERSION = '0.001'; # VERSION
5              
6 1     1   369 use 5.010001;
  1         2  
7 1     1   3 use strict;
  1         1  
  1         14  
8 1     1   3 use warnings;
  1         3  
  1         166  
9              
10             sub new {
11 1     1 1 1 my $class = shift;
12 1         4 my %args = (
13             format => 'DateTime',
14             returns => 'first',
15             prefers => 'nearest',
16             time_zone => 'floating',
17             @_,
18             );
19              
20 1 50       4 if ($args{format} ne 'DateTime') {
21 0         0 die "Invalid `format` passed to constructor: expected `DateTime'.";
22             }
23              
24 1 50       2 if ($args{returns} ne 'first') {
25 0         0 die "Invalid `returns` passed to constructor: expected `first'.";
26             }
27              
28 1 50       3 if ($args{prefers} ne 'nearest') {
29 0         0 die "Invalid `prefers` passed to constructor: expected `nearest'.";
30             }
31              
32 1   33     4 my $self = bless \%args, ref($class) || $class;
33              
34 1         3 return $self;
35             }
36              
37             sub extract {
38 1     1 1 10 state $parser = do {
39 1         537 require DateTime::Format::Alami::ID;
40 1         8051 DateTime::Format::Alami::ID->new;
41             };
42              
43 1         11 my $self = shift;
44 1         1 my $text = shift;
45 1         2 my %args = @_;
46              
47             # using extract as a class method
48 1 50       8 $self = $self->new
49             if !ref($self);
50              
51 1         5 $parser->parse_datetime($text);
52             }
53              
54             1;
55             # ABSTRACT: Extract probable dates from Indonesian text
56              
57             __END__