line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Command::generate::lexicon; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2938
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
71
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
62
|
|
5
|
3
|
|
|
3
|
|
1443
|
use utf8; |
|
3
|
|
|
|
|
24
|
|
|
3
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1221
|
use Mojo::Base 'Mojolicious::Command'; |
|
3
|
|
|
|
|
4331
|
|
|
3
|
|
|
|
|
10
|
|
8
|
3
|
|
|
3
|
|
236525
|
use String::Escape qw(qqbackslash); |
|
3
|
|
|
|
|
10308
|
|
|
3
|
|
|
|
|
223
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.997; |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
15
|
use File::Find; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
120
|
|
13
|
3
|
|
|
3
|
|
1949
|
use Getopt::Long; |
|
3
|
|
|
|
|
21182
|
|
|
3
|
|
|
|
|
10
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
1480
|
use MojoX::I18N::Lexemes; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
12
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->attr(description => <<'EOF'); |
18
|
|
|
|
|
|
|
Generate lexicon file from templates. |
19
|
|
|
|
|
|
|
EOF |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->attr(usage => <<"EOF"); |
22
|
|
|
|
|
|
|
usage: $0 generate lexicon [language] [--behavior=save||reset] [templates] |
23
|
|
|
|
|
|
|
Options: |
24
|
|
|
|
|
|
|
-b, --behavior=BEHAVIOR |
25
|
|
|
|
|
|
|
Determine how to work with existent lexems, possible values: |
26
|
|
|
|
|
|
|
save save old lexicon values; |
27
|
|
|
|
|
|
|
reset delete old lexicon. |
28
|
|
|
|
|
|
|
EOF |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub run { |
31
|
5
|
|
|
5
|
1
|
8846
|
my $self = shift; |
32
|
5
|
|
|
|
|
8
|
my $language = shift; |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
|
|
7
|
my @templates; |
35
|
|
|
|
|
|
|
my $app; |
36
|
5
|
50
|
|
|
|
14
|
if (ref $self->app eq 'CODE'){ |
37
|
5
|
|
|
|
|
36
|
$app = $self->app->(); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else{ |
40
|
0
|
|
|
|
|
0
|
$app = $self->app; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
5
|
|
|
|
|
395852
|
my $verbose; |
44
|
|
|
|
|
|
|
|
45
|
5
|
|
|
|
|
13
|
my $app_klass = ref $app; |
46
|
5
|
|
|
|
|
39
|
my $app_class = ref $app; |
47
|
5
|
|
|
|
|
12
|
$app_class =~ s{::}{/}g; |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
100
|
|
|
21
|
$language ||= 'Skeleton'; |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
6
|
my $behavior = ''; |
52
|
|
|
|
|
|
|
|
53
|
5
|
50
|
|
|
|
22
|
local @ARGV = @_ if @_; |
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
22
|
my $result = GetOptions( |
56
|
|
|
|
|
|
|
"behavior|b:s{1,1}" => \$behavior, |
57
|
|
|
|
|
|
|
'verbose|v:1' => \$verbose, |
58
|
|
|
|
|
|
|
); |
59
|
5
|
50
|
|
|
|
1298
|
push @templates, $ARGV[0] if (defined $ARGV[0]); |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
16
|
my $handler = $app->renderer->default_handler; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Find all templates of project |
64
|
5
|
50
|
|
|
|
38
|
unless (@templates) { |
65
|
|
|
|
|
|
|
find( |
66
|
|
|
|
|
|
|
sub { |
67
|
0
|
0
|
|
0
|
|
0
|
push @templates, $File::Find::name if (/\.$handler/); |
68
|
|
|
|
|
|
|
}, |
69
|
0
|
|
|
|
|
0
|
@{$app->renderer->paths} |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
5
|
|
|
|
|
14
|
my $lexem_file = $app->home->rel_file("lib/$app_class/I18N/$language.pm"); |
74
|
5
|
|
|
|
|
73
|
my %oldlex = (); |
75
|
|
|
|
|
|
|
|
76
|
5
|
100
|
|
|
|
104
|
if (-e $lexem_file) { |
77
|
3
|
50
|
|
|
|
26
|
if ($language ne 'Skeleton') { |
78
|
3
|
100
|
|
|
|
14
|
if (lc $behavior eq 'save') { |
|
|
50
|
|
|
|
|
|
79
|
2
|
|
|
|
|
4
|
%oldlex = eval { |
80
|
2
|
|
|
|
|
327
|
local %INC = %INC; |
81
|
2
|
|
|
|
|
19
|
require $app->home->rel_file("lib/$app_class/I18N/$language.pm"); |
82
|
3
|
|
|
3
|
|
905
|
no strict 'refs'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
922
|
|
83
|
2
|
|
|
|
|
6
|
%{*{"${app_klass}::I18N::${language}::Lexicon"}}; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
48
|
|
84
|
|
|
|
|
|
|
}; |
85
|
2
|
50
|
|
|
|
8
|
%oldlex = () if ($@); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif (lc $behavior eq 'reset') { |
88
|
|
|
|
|
|
|
# Just proceed |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
0
|
|
|
|
|
0
|
print <
|
92
|
|
|
|
|
|
|
Lexemes already exists. |
93
|
|
|
|
|
|
|
You must set `--behavior' to one of "reset" or "save". |
94
|
|
|
|
|
|
|
USAGE |
95
|
0
|
|
|
|
|
0
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
3
|
50
|
|
|
|
15
|
print " [delete] $lexem_file\n" unless $self->quiet; |
100
|
3
|
|
|
|
|
298
|
unlink $lexem_file; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
5
|
|
|
|
|
46
|
my $l = MojoX::I18N::Lexemes->new(); |
104
|
|
|
|
|
|
|
|
105
|
5
|
|
|
|
|
35
|
my %lexicon = %oldlex; |
106
|
|
|
|
|
|
|
|
107
|
5
|
|
|
|
|
11
|
foreach my $file (@templates) { |
108
|
5
|
50
|
|
|
|
119
|
open F, $file or die "Unable to open $file: $!"; |
109
|
5
|
|
|
|
|
9
|
my $t = do { local $/; }; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
56
|
|
110
|
5
|
|
|
|
|
23
|
close F; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# get lexemes |
113
|
5
|
100
|
|
|
|
14
|
print "Parsing $file \n" if $verbose; |
114
|
5
|
|
|
|
|
21
|
my $parsed_lexemes = $l->parse($t); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# add to all lexemes |
117
|
5
|
|
|
|
|
5
|
foreach (grep { !exists $lexicon{$_} } @{$parsed_lexemes}) { |
|
14
|
|
|
|
|
26
|
|
|
5
|
|
|
|
|
8
|
|
118
|
11
|
|
|
|
|
14
|
$lexicon{$_} = ''; |
119
|
11
|
100
|
|
|
|
47
|
print "New lexeme found => $_\n" if $verbose; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Output lexem |
124
|
5
|
|
|
|
|
39
|
$self->render_to_file('package', $lexem_file, $app_klass, $language, |
125
|
|
|
|
|
|
|
\%lexicon); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__DATA__ |