| 1 | package Telegram::CamshotBot::Util; | ||||||||||
| 2 | 1 | $Telegram::CamshotBot::Util::VERSION = '0.03'; | |||||||||
| 3 | # ABSTRACT: Reusable functions | ||||||||||
| 4 | |||||||||||
| 5 | # use Mojo::Base -strict; | ||||||||||
| 6 | # use base qw (Exporter); | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | 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 | 1 | ▶ | sub random_caption { | ||||||||
|
Subroutine
random_caption: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 19 | 1 | my $arr = shift; | |||||||||
| 20 | 1 | my @array = @$arr; | |||||||||
| 21 | 1 | my $index = rand @array; | |||||||||
| 22 | 1 | my $element = $array[$index]; | |||||||||
| 23 | 1 | return $element; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub first_existing_file { | ||||||||
|
Subroutine
first_existing_file: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 29 | 0 | my @files = @_; | |||||||||
| 30 | 0 | for my $filename (@files) { | |||||||||
| 31 | 0 | ▶ | if (-e $filename) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | return $filename; | |||||||||
| 33 | } | ||||||||||
| 34 | } | ||||||||||
| 35 | 0 | return undef; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub get_pm_from_mod { | ||||||||
|
Subroutine
get_pm_from_mod: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 40 | 0 | my $p = shift; # $p = package name | |||||||||
| 41 | 0 | my @s = split(/::/, $p); | |||||||||
| 42 | 0 | $p = join('::', $s[0], $s[1]); | |||||||||
| 43 | 0 | $p =~ s/::/\//g; | |||||||||
| 44 | 0 | $p =~ s/$/.pm/; | |||||||||
| 45 | # warn "inc :".$INC{$p}; | ||||||||||
| 46 | 0 | return $INC{$p}; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub abs_path_of_sample_mojo_conf { | ||||||||
|
Subroutine
abs_path_of_sample_mojo_conf: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | 0 | my $package = shift; | |||||||||
| 54 | 0 | my $pm_location = get_pm_from_mod($package); | |||||||||
| 55 | 0 | my $app_pm_basename = basename($pm_location); | |||||||||
| 56 | 0 | my $app_name = $app_pm_basename; | |||||||||
| 57 | 0 | $app_name =~ s/\.pm//; | |||||||||
| 58 | 0 | return dirname($pm_location).'/'.$app_name.".json.example"; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | 2 | ▶ | sub first_existing_variable { | ||||||||
|
Subroutine
first_existing_variable: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 63 | 2 | ▶ | for(@_){ return $_ if $_ } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | # return (grep{$_}@_)[0]; | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | 1 | *fev = \&first_existing_variable; | |||||||||
| 69 | 1 | *fef = \&first_existing_file; | |||||||||
| 70 | |||||||||||
| 71 | # sub fev {return first_existing_variable(@_);} | ||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | 1 | 1; | |||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||