File Coverage

blib/lib/Articulate/Enrichment/DateCreated.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition 1 3 33.3
subroutine 7 7 100.0
pod 1 1 100.0
total 31 33 93.9


line stmt bran cond sub pod time code
1             package Articulate::Enrichment::DateCreated;
2 4     4   2544 use strict;
  4         8  
  4         131  
3 4     4   18 use warnings;
  4         7  
  4         93  
4            
5 4     4   1987 use Text::Markdown;
  4         22511  
  4         188  
6 4     4   27 use Moo;
  4         10  
  4         31  
7            
8            
9             =head1 NAME
10            
11             Articulate::Enrichment::DateCreated - add a creation date to the meta
12            
13             =head1 METHODS
14            
15             =head3 enrich
16            
17             Sets the creation date (C) to the current time, unless it already has a defined value.
18            
19             =cut
20            
21 4     4   4041 use DateTime;
  4         320440  
  4         530  
22            
23             sub _now {
24 2     2   22 DateTime->now;
25             }
26            
27             sub enrich {
28 2     2 1 5 my $self = shift;
29 2         5 my $item = shift;
30 2         4 my $request = shift;
31 2         9 my $now = _now;
32 2   33     942 $item->meta->{schema}->{core}->{dateCreated} //= "$now";
33 2         108 return $item;
34             }
35            
36             1;