$ pwd /home/bob/Documents/meditations/castaways/translate/blib $ ls arch bin lib man1 man3 script $ #### my %WriteMakefileArgs = ( NAME => 'translate', AUTHOR => q{professor }, VERSION_FROM => 'lib/translate.pm', ABSTRACT_FROM => 'lib/translate.pm', LICENSE => 'artistic_2', MIN_PERL_VERSION => '5.006', CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => '0', }, TEST_REQUIRES => { 'Test::More' => '0', }, PREREQ_PM => { #'ABC' => '1.6', #'Foo::Bar::Module' => '5.0401', }, EXE_FILES => ['lib/1.my_script.pl'], dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'translate-*' }, ); #### $ pwd /home/bob/Documents/meditations/castaways/translate/lib $ cd .. $ ls Changes ignore.txt lib Makefile.PL MANIFEST README t xt $ perl Makefile.PL Checking if your kit is complete... Looks good WARNING: Setting ABSTRACT via file 'lib/translate.pm' failed at /usr/local/share/perl/5.26.1/ExtUtils/MakeMaker.pm line 753. Generating a Unix-style Makefile Writing Makefile for translate Writing MYMETA.yml and MYMETA.json $ make cp lib/translate.pm.bak blib/lib/translate.pm.bak cp lib/translate.pm blib/lib/translate.pm cp lib/my_data/lang_data/1.langlist.txt blib/lib/my_data/lang_data/1.langlist.txt cp lib/1.my_script.pl blib/lib/1.my_script.pl cp lib/1.my_script.pl blib/script/1.my_script.pl "/usr/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/1.my_script.pl Manifying 1 pod document $ make test PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/00-load.t ....... 1/? # Testing translate 0.01, Perl 5.026001, /usr/bin/perl t/00-load.t ....... ok t/manifest.t ...... skipped: Author tests not required for installation t/pod-coverage.t .. skipped: Author tests not required for installation t/pod.t ........... skipped: Author tests not required for installation All tests successful. Files=4, Tests=1, 1 wallclock secs ( 0.05 usr 0.01 sys + 0.41 cusr 0.08 csys = 0.55 CPU) Result: PASS $ make install Manifying 1 pod document Installing /home/bob/perl5/lib/perl5/translate.pm Installing /home/bob/perl5/lib/perl5/1.my_script.pl Installing /home/bob/perl5/lib/perl5/translate.pm.bak Installing /home/bob/perl5/lib/perl5/my_data/lang_data/1.langlist.txt Installing /home/bob/perl5/man/man3/translate.3pm Installing /home/bob/perl5/bin/1.my_script.pl Appending installation info to /home/bob/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/perllocal.pod $ ls blib ignore.txt Makefile MANIFEST MYMETA.yml README xt Changes lib Makefile.PL MYMETA.json pm_to_blib t $ #### package translate; use 5.006; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( get_config get_trans get_from_lang get_to_lang reverse_trans); our $VERSION = '0.01'; =head1 SYNOPSIS use translate; my $config = get_config('path-to-ini-file', $sub_hash); my $from = get_from_lang(); my $to = get_to_lang(); my $trans_output_file = get_trans($input_file, $from, $to, $config); my $reverse = reverse_trans($trans_output_file, $to, $from, $config); =cut sub get_config { use Config::Tiny; use Data::Dumper; use open OUT => ':encoding(UTF-8)'; use Path::Tiny; use 5.011; my ( $ini_path, $sub_hash ) = @_; say "ini path is $ini_path"; say "sub_hash is $sub_hash"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); say Dumper $Config; my $key = $Config->{$sub_hash}{'api_key_1'}; return $key; } sub get_from_lang { use Path::Tiny; use 5.011; my $von = 'en'; # put your default here say "Would you like to see the possibilities?"; my $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { my $path_to_langs = path( "my_data", "lang_data", "1.langlist.txt" ); my $data = $path_to_langs->slurp_utf8; say "$data"; } my $prompt2; say "Would you like to change the from language?"; $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { say "enter new lang: "; $prompt2 = ; chomp $prompt2; $von = $prompt2; } return $von; } sub get_to_lang { use Path::Tiny; use 5.011; my $zu = 'ru'; # put your default here say "Would you like to see the possibilities?"; my $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { my $path_to_langs = path( "my_data", "lang_data", "1.langlist.txt" ); my $data = $path_to_langs->slurp_utf8; say "$data"; } my $prompt2; say "Would you like to change the from language?"; $prompt1 = ; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { say "enter new lang: "; $prompt2 = ; chomp $prompt2; $zu = $prompt2; } return $zu; } 1; # End of translate #### #!/usr/bin/perl -w use 5.011; use WWW::Google::Translate; use Data::Dumper; use open OUT => ':utf8'; use Path::Tiny; use lib "."; use translate; binmode STDOUT, 'utf8'; my $ini_path = qw( /home/bob/Documents/html_template_data/3.values.ini ); my $sub_hash = "google"; my $key = get_config($ini_path, $sub_hash); my $von = get_from_lang(); my $zu = get_to_lang(); my $wgt = WWW::Google::Translate->new( { key => $key, default_source => $von, default_target => $zu, } ); my $r = $wgt->translate( { q => 'I wave my private parts at your aunties, you cheesy lot of second hand electric donkey-bottom biters.' } ); my $result = ""; for my $trans_rh ( @{ $r->{data}->{translations} } ) { $result = $trans_rh->{translatedText}; print $trans_rh->{translatedText}, "\n"; } #### require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( get_config get_trans get_from_lang get_to_lang reverse_trans);