I was hoping to see a response from bliako, as I've been nibbling away at his recent meditation git-push target for Makefile (via ExtUtils::MakeMaker). This response gets long without even trying, so more between readmore tags:
I started with functions. I see what you did with classes, but I'm just not there yet. The scoping just doesn't make sense yet when I still don't know where things will go in this filesystem.
I have some preliminary results. This is from STDOUT and is in pre-tags:
$ ./1.my_script.pl
ini path is /home/bob/Documents/html_template_data/3.values.ini
sub_hash is google
$VAR1 = bless( {
...
'google' => {
'api_key_1' => 'redacted'
},
...
}
}, 'Config::Tiny' );
Would you like to see the possibilities?
y
┌───────────────────────┬───────────────────────┬───────────────────────┐
│ Afrikaans - af │Bahasa Indonesia- id │ Русский - ru │
│ አማርኛ - am │ Igbo - ig │ يڌنس - sd │
│ ةيبرعلا - ar │ Íslenska - is │ සිංහල - si │
│ Azərbaycanca - az │ Italiano - it │ Slovenčina - sk │
│ башҡорт теле - ba │ 日本語 - ja │ Slovenščina - sl │
│ беларуская - be │ Basa Jawa - jv │ Gagana Sāmoa - sm │
│ български - bg │ ქართული - ka │ chiShona - sn │
│ বাংলা - bn │ Қазақ тілі - kk │ Soomaali - so │
│ Bosanski - bs │ ភាសាខ្មែរ - km │ Shqip - sq │
│ Català - ca │ ಕನ್ನಡ - kn │ српски -sr-Cyrl
│ Cebuano - ceb │ 한국어 - ko │ srpski -sr-Latn
│ Corsu - co │ Kurdî - ku │ Sesotho - st │
│ Čeština - cs │ Кыргызча - ky │ Basa Sunda - su │
│ Cymraeg - cy │ Latina - la │ Svenska - sv │
│ Dansk - da │ Lëtzebuergesch - lb │ Kiswahili - sw │
│ Deutsch - de │ ລາວ - lo │ தமிழ் - ta │
│ Ελληνικά - el │ Lietuvių - lt │ తెలుగు - te │
│ Emoji - emj │ Latviešu - lv │ Тоҷикӣ - tg │
│ English - en │ Malagasy - mg │ ไทย - th │
│ Esperanto - eo │ Олык марий - mhr │ Tagalog - tl │
│ Español - es │ Māori - mi │ tlhIngan Hol - tlh │
│ Eesti - et │ Македонски - mk │ tlh-Qaak
│ Euskara - eu │ മലയാളം - ml │ Lea faka-Tonga - to │
│ یسراف - fa │ Монгол - mn │ Türkçe - tr │
│ Suomi - fi │ मराठी - mr │ татарча - tt │
│ Vosa Vakaviti - fj │ Кырык мары - mrj │ Reo Tahiti - ty │
│ Français - fr │ Bahasa Melayu - ms │ удмурт - udm │
│ Frysk - fy │ Malti - mt │ Українська - uk │
│ Gaeilge - ga │ Hmoob Daw - mww │ وُدرُا - ur │
│ Gàidhlig - gd │ မြန်မာစာ - my │ Oʻzbek tili - uz │
│ Galego - gl │ नेपाली - ne │ Tiếng Việt - vi │
│ ગુજરાતી - gu │ Nederlands - nl │ isiXhosa - xh │
│ Hausa - ha │ Norsk - no │ שידִיי - yi │
│ ʻŌlelo Hawaiʻi - haw │ Nyanja - ny │ Yorùbá - yo │
│ תיִרְבִע - he │ Hñąñho - otq │ Màaya T'àan - yua │
│ हिन्दी - hi │ ਪੰਜਾਬੀ - pa │ 粵語 - yue │
│ Hmoob - hmn │ Papiamentu - pap │ 简体中文 - zh-CN│
│ Hrvatski - hr │ Polski - pl │ 正體中文 - zh-TW│
│ Kreyòl Ayisyen - ht │ وتښپ - ps │ isiZulu - zu │
│ Magyar - hu │ Português - pt │ │
│ Հայերեն - hy │ Română - ro │ │
└───────────────────────┴───────────────────────┴───────────────────────┘
Would you like to change the from language?
n
Would you like to see the possibilities?
n
Would you like to change the from language?
n
Я машу своими личными частями в твоих тетушек, ты, паршивая подержанная электрическая пила с ослиным дном.
then insert an EXE_FILES => 'bin/myscript.pl' into Makefile.PL
Is this the bin directory where 1.myscript.pl should end up?
$ pwd /home/bob/Documents/meditations/castaways/translate/blib $ ls arch bin lib man1 man3 script $
I did this:
my %WriteMakefileArgs = ( NAME => 'translate', AUTHOR => q{professor <prof@island.coconut>}, 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-*' }, );
I executed the make commands:
$ 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.l +anglist.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::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l +ib', '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 installatio +n t/pod-coverage.t .. skipped: Author tests not required for installatio +n t/pod.t ........... skipped: Author tests not required for installatio +n 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 $
This is what the package looks like now:
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 = <STDIN>; 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 = <STDIN>; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { say "enter new lang: "; $prompt2 = <STDIN>; 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 = <STDIN>; 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 = <STDIN>; chomp $prompt1; if ( $prompt1 eq ( "y" | "Y" ) ) { say "enter new lang: "; $prompt2 = <STDIN>; chomp $prompt2; $zu = $prompt2; } return $zu; } 1; # End of translate
and this is what 1.myscript.pl looks like:
#!/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 aunti +es, 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"; }
My first question is whether I had to use
require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( get_config get_trans get_from_lang get_to_lang reverse_trans);
as I have done in previous modules. Page 183 of _Intermediate Perl_ seems to suggest that I could name them in an export section. Is that only for documentation?
My other general question is where files should go. What does the t directory do? How about xt?
When do you start with git?
Thanks for your comments,
In reply to Re^4: installing module starter
by Aldebaran
in thread installing module starter
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |