|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Mojolicious::Command::generate::lexicon;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
1556
 | 
 use strict;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
69
 | 
    | 
| 
4
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
8
 | 
 use warnings;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
63
 | 
    | 
| 
5
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
1408
 | 
 use utf8;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
7
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
1109
 | 
 use Mojo::Base 'Mojolicious::Command';  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18556
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
    | 
| 
8
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
246731
 | 
 use String::Escape qw(qqbackslash);  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10270
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
214
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = 0.996;  | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
12
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
17
 | 
 use File::Find;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
150
 | 
    | 
| 
13
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
1982
 | 
 use Getopt::Long;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
21339
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
    | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
15
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
1750
 | 
 use MojoX::I18N::Lexemes;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
    | 
| 
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
  
 | 
29882
 | 
     my $self     = shift;  | 
| 
32
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
     my $language = shift;  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     my @templates;  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $app;  | 
| 
36
 | 
5
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
16
 | 
     if (ref $self->app eq 'CODE'){  | 
| 
37
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
43
 | 
         $app = $self->app->();  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     else{  | 
| 
40
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         $app = $self->app;  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
43
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
414236
 | 
     my $verbose;  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
       | 
| 
45
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
     my $app_klass = ref $app;  | 
| 
46
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
53
 | 
     my $app_class = ref $app;  | 
| 
47
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
     $app_class =~ s{::}{/}g;  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
49
 | 
5
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
28
 | 
     $language ||= 'Skeleton';  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
51
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     my $behavior = '';  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
5
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
30
 | 
     local @ARGV = @_ if @_;  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
55
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
     my $result = GetOptions(  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         "behavior|b:s{1,1}" => \$behavior,  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         'verbose|v:1'        => \$verbose,  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     );  | 
| 
59
 | 
5
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
1542
 | 
     push @templates, $ARGV[0] if (defined $ARGV[0]);  | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
61
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
     my $handler = $app->renderer->default_handler;  | 
| 
62
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Find all templates of project  | 
| 
64
 | 
5
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
48
 | 
     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
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
     my $lexem_file = $app->home->rel_file("lib/$app_class/I18N/$language.pm");  | 
| 
74
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
97
 | 
     my %oldlex     = ();  | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
76
 | 
5
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
122
 | 
     if (-e $lexem_file) {  | 
| 
77
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
40
 | 
         if ($language ne 'Skeleton') {  | 
| 
78
 | 
3
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
19
 | 
             if (lc $behavior eq 'save') {  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
79
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
                 %oldlex = eval {  | 
| 
80
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
580
 | 
                     require "$app_class/I18N/$language.pm";  | 
| 
81
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
941
 | 
                     no strict 'refs';  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
861
 | 
    | 
| 
82
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9456
 | 
                     %{*{"${app_klass}::I18N::${language}::Lexicon"}};  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
17
 | 
    | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 };  | 
| 
84
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
12
 | 
                 %oldlex = () if ($@);  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             elsif (lc $behavior eq 'reset') {  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 # Just proceed  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             else {  | 
| 
90
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 print <
 | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Lexemes already exists.  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 You must set `--behavior' to one of "reset" or "save".  | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 USAGE  | 
| 
94
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 return;  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
98
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
21
 | 
         print "  [delete] $lexem_file\n" unless $self->quiet;  | 
| 
99
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
282
 | 
         unlink $lexem_file;  | 
| 
100
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
102
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
56
 | 
     my $l = MojoX::I18N::Lexemes->new();  | 
| 
103
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
104
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
     my %lexicon = %oldlex;  | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
106
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
     foreach my $file (@templates) {  | 
| 
107
 | 
5
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
145
 | 
         open F, $file or die "Unable to open $file: $!";  | 
| 
108
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
         my $t = do { local $/;  };  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
21
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
59
 | 
    | 
| 
109
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
25
 | 
         close F;  | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         # get lexemes  | 
| 
112
 | 
5
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
         print "Parsing $file \n" if $verbose;  | 
| 
113
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
25
 | 
         my $parsed_lexemes = $l->parse($t);  | 
| 
114
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
115
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         # add to all lexemes  | 
| 
116
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
         foreach (grep { !exists $lexicon{$_} } @{$parsed_lexemes}) {  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
    | 
| 
117
 | 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
             $lexicon{$_} = '';  | 
| 
118
 | 
11
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
26
 | 
             print "New lexeme found => $_\n" if $verbose;  | 
| 
119
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
120
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Output lexem  | 
| 
123
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
50
 | 
     $self->render_to_file('package', $lexem_file, $app_klass, $language,  | 
| 
124
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         \%lexicon);  | 
| 
125
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
126
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
127
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
129
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __DATA__  |