Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Bod

by Bod (Vicar)
on Nov 15, 2020 at 00:48 UTC ( #11123653=user: print w/replies, xml ) Need Help??

Long time amateur coder since growing up with a ZX Spectrum and BBC Micro...

Introduced to Perl in the early 1990's which quickly became the language of choice. Built many websites and backend applications using Perl including the sites for my property business:
Lets Delight - company site
Lets Stay - booking site
Also a few simple TK based desktop apps to speed things up.

Guilty of only learning what I need to get the job done - a recipe for propagating bad practice and difficult to maintain code...difficult for me so good luck to anyone else!

Now (Nov 2020) decided to improve my coding skills although I'm not really sure what "improve" means in this context. It seems Perl and best practice have come along way since I last checked in and my programming is approach is stuck in the last decade.

Onwards and upwards...

20th October 2021 - added to Saint in our Book 😀
2nd October 2022 - promoted to Priest
7th July 2023 - promoted to Vicar


Find me on LinkedIn


CPAN Release

Business::Stripe::WebCheckout


Posts by Bod
Deciding dependency versions in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
by Bod
on Jun 09, 2023 at 18:52

    When releasing a new module, how do you decide which minimum version of the dependencies to require?

    I am about to release Business::Stripe::Webhook and it has these dependencies in Makefile.PL:

    PREREQ_PM => { 'JSON::PP' => '2.00', 'HTTP::Tiny' => '0.014', 'Digest::SHA' => '5.94', 'Time::Piece' => '1.32', },
    The modules I have selected are all core. I've approached the minimum version by firstly checking what version I have installed. That sets the maximum I need to specify. Then to look at the module's CHANGES file and work back until I see a change that I think might affect my module and select the version after that.

    I strongly suspect that I could go for earlier ones but don't want to risk my code breaking because of a broken dependency. That's just annoying and frustrating for everyone. Equally, I don't want to force people to update every module if it is not necessary.

    So, how do you select the minimum version number for your dependencies?

Version Control - GitHub and CPAN in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
by Bod
on Jun 09, 2023 at 16:16

    More Monastic Wisdom is rubbing off on me...I am uploading (git committing?) AI::Embedding following nudges from hippo and others, but especially GrandFather in Re^3: What is ignore.txt

    Questions as usual...

    1 - Is there a convention I should be using for naming Perl repositories?
    I have looked at others and some start p5-... - I assume that was to distinguish them from Perl 4 but is that a concern now? Others use perl-... and others just the name of the module. Is there a preferred way to do it that I should follow?

    2 - Am I right that GitHub and CPAN are not connected?
    There is no means for changes within GitHub to be reflected on CPAN other than by uploading a tarball in the usual way. GitHub is "just" (hardly "just" but I hope you understand!) a place to store, collaborate and develop code. CPAN is the repository where it gets installed to.

    3 - Should I have different GitHub accounts for different purposes?
    In time I will be releasing a JavaScript library for one of my businesses (On Radar) to allow web developers to interact with our CRM product. If this ends up on GitHub does it need a different account? If so, is it because it is for the business or because it is in a different language?

    I understand the value but also want to do it right. I've had a few people contact me with suggestions for Business::Stripe::WebCheckout, some have sent useful code snippets that have been included or will be included in a later release. Surprising as I didn't really think anyone would find it useful! If it were on GitHub like it will be, they could have done a pull request and I wouldn't have to insert their code...just approve the PR and build a new release periodically :)

What is ignore.txt in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Bod
on Jun 08, 2023 at 13:47

    I am trying to 'properly' build AI::Embedding and publish the next development version to CPAN. So, as kcott suggested, I have turned on RELEASE_TESTING and I am running the tests using prove. My user tests are now passing but I am stuck on the author tests.

    Attempting to prove -vb t/manifest.t I get the following error:

    not ok 1# The following files are not named in the MANIFEST file: C:\U +sers\user\Perl\AI-Embedding\AI-Embedding\ignore.txt, C:\Users\user\Pe +rl\AI-Embedding\AI-Embedding\t\01-openai.t, C:\Users\user\Perl\AI-Emb +edding\AI-Embedding\xt\boilerplate.t
    All these files were created by Module::Starter.

    What is ignore.txt used for and does it need to be added to the manifest file?

    What is a xt directory for? Can I ignore or delete it?

    For slightly later, once I've built the module, should I delete the blib directory before make dist?

    Also, because I have AI::Embedding v0.1_1 installed, I had to add use lib 'lib'; to the test files to make the tests use the right version of the module. Will this create difficulties if it is left in when the module gets uploaded to CPAN?

Multidimensional arrays in Seekers of Perl Wisdom
5 direct replies — Read more / Contribute
by Bod
on Jun 06, 2023 at 10:55

    We operate a few sites with subscriptions. Until recently, the subscription cost has been fixed with just three plan options - monthly, 6 monthly or annually. However, we now want to increase the cost on one site for new members but not existing members. Existing members will have their current subscription rate locked for life.

    Currently, the three subscription rates are declared in a parameters file:

    our $stripe_price_1 = 'price_123245'; our $stripe_price_6 = 'price_123267'; our $stripe_price_12 = 'price_123289';
    The price code is passed to Stripe during the checkout process.

    Having multiple prices in the future means we need to adopt a different approach. Users have the option to change between payment plans so they can swap from monthly or annually, etc. Therefore, we need to know which pricing level they are on as well as the plan. We can (and currently do) easily get the plan from Stripe. But getting the level is more tricky. We'd have to get the price code and work backwards.

    So, I am thinking of adding two fields to the Subscription table of the database - priceLevel and pricePlan - and replacing the above declarations with a two dimensional Perl array of hashref:

    my @price; $price[1,1] = { 'name' => 'Early Adopter', 'plan' => 1, 'length' => 1, 'price' => 3.49, 'stripe' => 'price_123245', }; $price[1,6] = { 'name' => 'Early Adopter', 'plan' => 1, 'length' => 6, 'price' => 18.99, 'stripe' => 'price_123267', }; $price[1,12] = { 'name' => 'Early Adopter', 'plan' => 1, 'length' => 12, 'price' => 32.49, 'stripe' => 'price_123289', }; $price[2,1] = { 'name' => 'First Increase', 'plan' => 2, 'length' => 1, 'price' => 3.99, 'stripe' => 'price_123445', }; $price[2,6] = { ... }; $price[2,12] = { 'name' => 'First Increase', 'plan' => 2, 'length' => 12, 'price' => 33.99, 'stripe' => 'price_123489', }; $price[3,1] = { ... }; $price[3,6] = { ... }; $price[3,12] = { ... };
    The two dimensions of the array corresponding to the two newly added database fields.

    I have two doubts about this approach...

    1. There are lots of 'spaces' in the array
    2. I seem to recall reading (probably) in The Monastry that multidimensional arrays are not a good idea

    Any advice very welcome...

Please review documentation of my AI::Embedding module in Meditations
2 direct replies — Read more / Contribute
by Bod
on Jun 02, 2023 at 17:26

    Could you please take a look at the documentation for my new module and let me know if it makes sense? I always find that I am too close to the module and know what everything is supposed to do. In short, I have the Curse of Knowledge!

    Here is the documentation

    Why is it you only find typos after publishing?
    The second raw_embedding method should read test_embedding in both the heading and the sample code. I've corrected this error now.

    Thank you greatly for helping me get this right...

    Edit:

    Changed title from "RFC - Documentation Review" to "Please review documentation of my AI::Embedding module" as considered by erzuuli

CPAN Testers in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Bod
on May 30, 2023 at 17:46
Test::More fails... in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Bod
on May 29, 2023 at 19:25

    My experience of tests is very limited so the experience of The Monestry is greatly appreciated

    I am using Test::More and I have two issues.

    Firstly...

    #!perl use 5.006; use strict; use warnings; use Test::More; plan tests => 1; BEGIN { use_ok( 'AI::Embedding' ) || print "Bail out!\n"; } diag( "Testing AI::Embedding $AI::Embedding::VERSION, Perl $], $^X" );
    This fails at plan tests => 1; despite this being added by Module::Starter and it appearing correct according to the documentation. Instead, I have to write use Test::More tests => 1;. What am I doing wrong?

    Second issue...

    my $comp_pass1 = $embed_pass->compare('-0.6,-0.5,-0.4,-0.3,-0.2,0.0,0. +2,0.3,0.4,0.5', '-0.6,-0.5,-0.4,-0.3,-0.2,0.0,0.2,0.3,0.4,0.5'); ok( $comp_pass1 == 1, "Compare got $comp_pass1"); $embed_pass->comparator('-0.6,-0.5,-0.4,-0.3,-0.2,0.0,0.2,0.3,0.4,0.5' +); my $comp_pass2 = $embed_pass->compare('-0.6,-0.5,-0.4,-0.3,-0.2,0.0,0. +2,0.3,0.4,0.5'); ok( $comp_pass2 == 1, "Compare to comparator got $comp_pass2");
    This code is failing despite $comp_pass1 and $comp_pass2 being 1. Again, what am I doing wrong?

    This is the output from gmake test

    "C:\Strawberry\perl\bin\perl.exe" "-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/1 # Testing AI::Embedding 0.1_1, Perl 5.032001, +C:\Strawberry\perl\bin\perl.exe t/00-load.t ....... ok t/01-openai.t ..... 1/11 # Failed test 'Compare to comparator got 1' # at t/01-openai.t line 44. # Looks like you failed 1 test of 11. t/01-openai.t ..... Dubious, test returned 1 (wstat 256, 0x100) Failed 1/11 subtests 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 Test Summary Report ------------------- t/01-openai.t (Wstat: 256 Tests: 11 Failed: 1) Failed test: 11 Non-zero exit status: 1 Files=5, Tests=12, 0 wallclock secs ( 0.05 usr + 0.02 sys = 0.06 CP +U) Result: FAIL Failed 1/5 test programs. 1/12 subtests failed. gmake: *** [Makefile:859: test_dynamic] Error 255

How Critical is Critic? in Seekers of Perl Wisdom
8 direct replies — Read more / Contribute
by Bod
on May 28, 2023 at 20:18

    As the new module is pretty much written I have thrown it at Perl Critic which has detected a couple of issues. But as I have wound up the severity, it seems a little silly...

    How critical is it that code destined for CPAN passes critic, if at all?
    And what severity level would be sensible?

    I was surprised it didn't like this use of eval:

    our $VERSION = '0.1_1'; $VERSION = eval $VERSION;
    and I struggle to see what benefit adding the /x flag would be to such a simple regular expression:
    my @embed = split /,/, $embed_string;
    With a higher severity, it wants me to add lots of flags - /xms - to this!

    The one where I want to change it but can't quite see a better way to write it without losing clarity is this:

    # Create Embedding object sub new { my $class = shift; my %attr = @_; # ...... }
    Critic says I should unpack @_ on the first line but is it really that bad to split it across two consecutive lines? There would be a problem if it was part way through the sub but it is clear what is going on and there is no chance of the modifying the wrong thing through an alias.

    Am I missing some lurking danger here?

CPAN Ratings... in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
by Bod
on May 28, 2023 at 19:41

    I've had a bug reported for Business::Stripe::WebCheckout regarding CPAN Ratings.

    This report points out that "CPAN Ratings" no longer exists but it is in my documentation. I didn't explicitly put that in the documentation so it must have been in template or perhaps copied from some other documentation.

    What was CPAN Ratings?
    Why isn't it there anymore?
    Do I need to do anything about it?

CPAN namespace for AI Embedding module in Meditations
1 direct reply — Read more / Contribute
by Bod
on May 28, 2023 at 17:41

    Wise Monks...

    Having written some code that uses Embeddings to compare pieces of text, I feel this would be useful to others. The Embeddings are generated from the OpenAI API at present.

    I plan to package this up into a module for CPAN and would like some advice on the namespace for this module...

    There is already OpenAI::API::Request::Embedding, which is just a thin wrapper to the API. I don't want to use the OpenAI namespace because my module will probably allow other Embedding providers to be used. For example, Hugging Face provides a cheaper but less precise Embeddings API. This may be better suited to some users.

    As well as providing the connection to the API, my module will also have a method to allow two pieces of text to be compared. More functionality than just a thin wrapper.

    I've looked at the AI namespace - e.g. AI::XGBoost. There is also Text::AI::CRM114

    As my module will connect to several different API providers, I am thinking AI::Embedding might be the right name for it but I am not convinced and your opinions and advice would be greatly appreciated.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2023-06-10 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (39 votes). Check out past polls.

    Notices?