line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Telegram::CamshotBot::Util; |
2
|
|
|
|
|
|
|
$Telegram::CamshotBot::Util::VERSION = '0.01'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Reusable functions |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# use Mojo::Base -strict; |
6
|
|
|
|
|
|
|
# use base qw (Exporter); |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
13983
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
9
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
10
|
1
|
|
|
1
|
|
537
|
use Data::Dumper; |
|
1
|
|
|
|
|
6933
|
|
|
1
|
|
|
|
|
296
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
13
|
|
|
|
|
|
|
qw(first_existing_file fef get_pm_from_mod random_caption abs_path_of_sample_mojo_conf first_existing_variable fev) |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub random_caption { |
19
|
1
|
|
|
1
|
1
|
9
|
my $arr = shift; |
20
|
1
|
|
|
|
|
3
|
my @array = @$arr; |
21
|
1
|
|
|
|
|
26
|
my $index = rand @array; |
22
|
1
|
|
|
|
|
3
|
my $element = $array[$index]; |
23
|
1
|
|
|
|
|
4
|
return $element; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub first_existing_file { |
29
|
0
|
|
|
0
|
0
|
0
|
my @files = @_; |
30
|
0
|
|
|
|
|
0
|
for my $filename (@files) { |
31
|
0
|
0
|
|
|
|
0
|
if (-e $filename) { |
32
|
0
|
|
|
|
|
0
|
return $filename; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
0
|
return undef; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub get_pm_from_mod { |
40
|
0
|
|
|
0
|
0
|
0
|
my $p = shift; # $p = package name |
41
|
0
|
|
|
|
|
0
|
my @s = split(/::/, $p); |
42
|
0
|
|
|
|
|
0
|
$p = join('::', $s[0], $s[1]); |
43
|
0
|
|
|
|
|
0
|
$p =~ s/::/\//g; |
44
|
0
|
|
|
|
|
0
|
$p =~ s/$/.pm/; |
45
|
|
|
|
|
|
|
# warn "inc :".$INC{$p}; |
46
|
0
|
|
|
|
|
0
|
return $INC{$p}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub abs_path_of_sample_mojo_conf { |
53
|
0
|
|
|
0
|
1
|
0
|
my $package = shift; |
54
|
0
|
|
|
|
|
0
|
my $pm_location = get_pm_from_mod($package); |
55
|
0
|
|
|
|
|
0
|
my $app_pm_basename = basename($pm_location); |
56
|
0
|
|
|
|
|
0
|
my $app_name = $app_pm_basename; |
57
|
0
|
|
|
|
|
0
|
$app_name =~ s/\.pm//; |
58
|
0
|
|
|
|
|
0
|
return dirname($pm_location).'/'.$app_name.".json.example"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub first_existing_variable { |
63
|
2
|
100
|
|
2
|
1
|
366
|
for(@_){ return $_ if $_ } |
|
6
|
|
|
|
|
21
|
|
64
|
|
|
|
|
|
|
# return (grep{$_}@_)[0]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
*fev = \&first_existing_variable; |
69
|
|
|
|
|
|
|
*fef = \&first_existing_file; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# sub fev {return first_existing_variable(@_);} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |