line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::ShortNameProvider::Style::Basic; |
2
|
|
|
|
|
|
|
$Data::ShortNameProvider::Style::Basic::VERSION = '1.000'; |
3
|
1
|
|
|
1
|
|
453
|
use POSIX qw( strftime ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
59
|
use Sub::Quote qw( quote_sub ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
3
|
use Time::Local qw( timegm ); |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
31
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
209
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Data::ShortNameProvider::Role::Style'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has version => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
default => '1', |
15
|
|
|
|
|
|
|
isa => quote_sub( << 'ISA' ), |
16
|
|
|
|
|
|
|
my ($v) = @_; |
17
|
|
|
|
|
|
|
die "'$v' is not a integer" if $v !~ /^(?:0|[1-9][0-9]*)$/; |
18
|
|
|
|
|
|
|
ISA |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has prefix => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
default => 'dsnp', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# derived attributes |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has timestamp => ( |
29
|
|
|
|
|
|
|
is => 'lazy', |
30
|
|
|
|
|
|
|
init_arg => undef, |
31
|
12
|
|
|
12
|
|
933
|
builder => sub { strftime '%y%m%d', gmtime shift->timestamp_epoch; }, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has parsing_regexp => ( |
35
|
|
|
|
|
|
|
is => 'lazy', |
36
|
|
|
|
|
|
|
init_arg => undef, |
37
|
|
|
|
|
|
|
builder => sub { |
38
|
4
|
|
|
4
|
|
317
|
my ($self) = @_; |
39
|
4
|
|
|
|
|
22
|
my $re = quotemeta( $self->prefix ) # prefix |
40
|
|
|
|
|
|
|
. '(0|[1-9][0-9]*)_' # version |
41
|
|
|
|
|
|
|
. '([0-9][0-9])(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])__' # timestamp |
42
|
|
|
|
|
|
|
. '(.*)'; # name |
43
|
4
|
|
|
|
|
203
|
return qr/^$re$/; |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub generate_name { |
48
|
16
|
|
|
16
|
1
|
3136
|
my ( $self, $name ) = @_; |
49
|
|
|
|
|
|
|
return |
50
|
16
|
|
|
|
|
341
|
$self->prefix |
51
|
|
|
|
|
|
|
. $self->version . '_' |
52
|
|
|
|
|
|
|
. $self->timestamp . '__' |
53
|
|
|
|
|
|
|
. $name; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub parse_generated_name { |
57
|
16
|
|
|
16
|
1
|
2650
|
my ( $self, $short_name ) = @_; |
58
|
16
|
100
|
|
|
|
317
|
return undef if $short_name !~ $self->parsing_regexp; |
59
|
|
|
|
|
|
|
return { |
60
|
8
|
|
|
|
|
152
|
prefix => $self->prefix, |
61
|
|
|
|
|
|
|
version => $1, |
62
|
|
|
|
|
|
|
timestamp => "$2$3$4", |
63
|
|
|
|
|
|
|
timestamp_epoch => timegm( 0, 0, 0, $4, $3 - 1, $2 ), |
64
|
|
|
|
|
|
|
name => $5, |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub is_generated_name { |
69
|
8
|
|
|
8
|
1
|
2828
|
my ( $self, $short_name ) = @_; |
70
|
8
|
|
|
|
|
146
|
return scalar $short_name =~ $self->parsing_regexp; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |