line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::ShortNameProvider::Style::Basic; |
2
|
|
|
|
|
|
|
$Data::ShortNameProvider::Style::Basic::VERSION = '1.001'; |
3
|
1
|
|
|
1
|
|
443
|
use POSIX qw( strftime ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
60
|
use Sub::Quote qw( quote_sub ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
3
|
use Time::Local qw( timegm ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
215
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
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
|
|
688
|
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
|
|
289
|
my ($self) = @_; |
39
|
4
|
|
|
|
|
15
|
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
|
|
|
|
|
166
|
return qr/^$re$/; |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub generate_name { |
48
|
16
|
|
|
16
|
1
|
1746
|
my ( $self, $name ) = @_; |
49
|
|
|
|
|
|
|
return |
50
|
16
|
|
|
|
|
251
|
$self->prefix |
51
|
|
|
|
|
|
|
. $self->version . '_' |
52
|
|
|
|
|
|
|
. $self->timestamp . '__' |
53
|
|
|
|
|
|
|
. $name; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub parse_generated_name { |
57
|
16
|
|
|
16
|
1
|
1150
|
my ( $self, $short_name ) = @_; |
58
|
16
|
100
|
|
|
|
187
|
return undef if $short_name !~ $self->parsing_regexp; |
59
|
|
|
|
|
|
|
return { |
60
|
8
|
|
|
|
|
108
|
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
|
1300
|
my ( $self, $short_name ) = @_; |
70
|
8
|
|
|
|
|
84
|
return scalar $short_name =~ $self->parsing_regexp; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |