Baby Moose in a Pen

Still stuck in the Accessor.pm in the Moose-pen today.

Since I decided in yesterday's post to make one more round of changes I am a little closeer to getting back to Driver::DBI but not much.

For today's changes I decided to go full out and re-factor a good chunk of the common code between Accessor.pm and any DAD that I might write. Not to bore you with reamls of code pasting you will never read I will give you the over-view.

First action was to strip out the attributes from Database::Accessor::Roles::Driver and Database::Accessor that where the same and put them into a new role 'Database::Accessor::Roles::Common'. My Driver Role is now just a few lines

Virtual Spring Cleaning Interlude: A herd of yaks, all waiting to be shaved

In my long-term quest to host all of my data on my systems, one of the major points is to replace the note-taking app Google Keep with something that allows me to take my notes back to me. I've looked at various open-source apps for taking and synchronizing notes, but they either feel like overdesigned monsters that don't fit my workflow (Laverna) or don't have good synchronization from mobile phone to the server.

Sydney Perl Mongers: April Meeting

You are invited to join us for this months Sydney PM meeting. We are hosted for the fist time by BarNet and we are glad and grateful for their invitation.

Everyone with an interest is welcome regardless of your experience with Perl and although we appreciate people RSVP'ing on Meetup, there is no need. Feel free to show up (and bring a friend) if you can make it.

There will be two speakers.

Lloyd will be speaking on his config management system, written in perl6

Brendan will be speaking about HashiCorp's Vault software, and how you can make use of it in your systems

When? Tuesday, April 18, 2017 6:00 PM

Where? BarNet ( Technology Dispute Centre ) 7/155 King Street, Sydney (St James Station is probably closest)


Find us on Meetup.com or Facebook

MVC::Neaf - Not Even A (Web Application) Framework

Hello everyone, today I'd like to present Neaf [ni:f], a web tool that tries hard to stay out of the way. Initially it was started for my own education. However, the result may be worth looking at even for users of serious stuff like Mojo, Dancer, and Kelp.

The main usage scenarios are perhaps sharing an existing module or script via the network, as well as supplementary tools and admin interfaces.

Baby Moose almost ready

Test case clean up day today in the Moose-Pen

All those changes I introduced in my last post did quite a job in mucking up my test suite as the latest run results show;

Files=27, Tests=328, 39 wallclock secs ( 0.24 usr  0.06 sys + 36.90 cusr  1.92 csys = 39.12 CPU)
Result: FAIL
Failed 9/27 test programs. 37/328 subtests failed.
The first thing I noticed was not a fail in a test but this warning;

Use of uninitialized value in string eq at …/lib/Database/Accessor.pm line 37.
coming up all over the place, I should of caught earlier but that is why we run tests. A little change in my 'around BUILDARGS' sub;

Golang's 'defer' in Perl

My day job involves programming in Go. One feature I like about Go is "defer". Any function that's deferred gets ran at the end of the functions scope. As a very simple example, the program below prints

hello
world

instead of the other way around, because "world" is deferred until the main() function exits.

package main
import "fmt"

func main() {
    defer fmt.Println("world")
    fmt.Println("hello")
}

How fast can you try?

I just saw the release of Aristotle's Try::Tiny::Tiny to CPAN, which aims to speed up Try::Tiny. That led me to wonder how fast the various Try* modules were. I cannibalized the benchmark code from Try::Catch, and off I went.

Timeouts for Parallel::ForkManager

At tonight's Chicago Perl Mongers Office Hours, Ray came up with an interesting problem. While testing all of CPAN for CPAN Testers, how do you detect when a test is hanging and kill it before it takes down the entire machine? How do you simply kill a test that is taking too long? And how do you do it without having a wholly separate watchdog program?

Ray's using Parallel::ForkManager to execute testing jobs in parallel across multiple Perl installs. There are a few ways we could implement timeouts, including IPC::Run's timeout function, or the alarm Perl built-in, but these must all be implemented in the child process. It'd be nicer if we could use the parent process to watch its own children.

Baby Moose Promise

It is keeping promises day here in the Moose-pen

Keeping in step with yesterday's post I am continuing with my code-review of Accessor.pm. It was suggested that I explain a little more on my reasons for doing most of the validation on the Accessor.pm side rater than the DAD side so here we go.

As today’s title suggests I want to make a promise to the DAD from the Accessor.pm that all the attributes that I have passed down to it are ready to go into a the requested CRUD query, so only a minimal amount of extra Database::Accessor::Driver logic is required.

What this mean is that I will have to carefully explain to potential users that the Update and Create methods only work with the initial set of 'Elements' and only with elements that have the same View. I have already did this one in yesterday's post.

An interesting memory hog

So last day I with a colleague got to trace an interesting memory leak ( which was rather a memory waste than a leak ). It was using tens of gigabytes of RAM, whereas I wouldn't expect it to use more than 3-4GB.

Call it a witchcraft if you like, but we identified line to blame within first minutes we started looking at the problem. Unfortunately, we were not able to convince each other that it is the issue and as the problem was only visible in a long running soak test we were not able to justify running it.

Perl's garbage collection works by reference counting and only frees circular references at exit. As we were dealing with a long running daemon - we started by trying to locate circular references. Inspecting code gave nothing away. So we decided to utilise wonderful Paul Evans' Devel::MAT module. Unfortunately we were not able to locate any circular references.

Virtual Spring Cleaning (part 1 of XX / 2017) - in which I hear CPANs call

Virtual Spring Cleaning (part 1 of XX / 2017) - in which I look who's calling

I really like the products by AVM, especially their Fritz!Box line of VoIP+DSL modems. For a long time, I've wanted to synchronize my CardDAV contacts from my server to my Fritz!Box, so that the reverse number lookup works on my landline as well as my mobile phone.

Perl 5 Porters Mailing List Summary: April 4th-10th

Hey everyone,

Following is the p5p (Perl 5 Porters) mailing list summary for the past week.

Enjoy!

Backtracking Baby Moose

Well no progress day here in the Moose-Pen

After yesterday's post where I decided to much more validation on the Accessor side of things I had a chance to takke a deep and close look at Accessor.pm.

A code review is always a good thing and I found a few problems right from the start, in mose of my CRUD functions I was still doing this

return $container; 
which is dead wrong and funny thing I did not have a check for this. So today I added that in with a simple change to 20_dad_load.t

ok($da_new->$type(Data::Test->new(),$container),"$type Query ran");
--ok($da_new->$type(Data::Test->new(),$container) == 1,"$type Query ran");

Dependency phases in CPAN distribution metadata

In the previous article in this series we gave a general introduction to the distribution metadata which is included in releases as files META.json and/or META.yml. In this article I'll drill into more detail at one critical component of a distribution's metadata: dependencies, also known as prerequisites (usually shortened to "prereqs"). This is how you specify other CPAN modules that your distribution depends on.

This post is brought to you by Booking.com, a platinum sponsor for the Perl Toolchain Summit. Booking.com is one of the largest Perl shops in the world, and so depends heavily on the toolchain. Thank you to Booking.com for supporting the summit.

Dist::Zilla @Starter - Revision 2

I recently released revision 2 of the [@Starter] plugin bundle for Dist::Zilla. This revision brings small improvements to the default behavior, as well as the option to set a different installer plugin. In order to use the new revision, you must set the option "revision = 2" when using the bundle.

Revision 2 uses [Pod2Readme] instead of [ReadmeAnyFromPod] to generate the text README file. [ReadmeAnyFromPod] is a great and flexible plugin, but [Pod2Readme] is much simpler for the specific purpose of generating a text README. For any additional README files in other formats, I still recommend using [ReadmeAnyFromPod].

This revision also sets the option "inherit_version" in [MetaProvides::Package] to 0 by default. This makes no difference if your distribution contains uniform module versions, or for modules which have no version (they are still marked as having the distribution version unless you set "inherit_missing" to 0 as well), but if you have modules with different versions hardcoded, this will reflect that in the "provides" metadata.

Virtual Spring Cleaning Prelude: What I did, and what hasn't happened so far

While trying to get some more of my modules ready for release, I've been doing drive-by patches to CPAN modules that I used for various reasons. While I'm not exactly enthused about throwing a patch with a testcase over the fence, I think it's still far better to have the problem and solution in some bug tracker somewhere than having it only on my hard drive.

Baby Moose Back Again?

Well its Accessor.pm post-ette day today here in the Moose-Pen

Yesterday's post I managed to make a very small start on my Driver::DBI before I figured it would be a good idea to do more of the param validation on the Accessor side rather than the driver side. That way I know I will not run into the situation where one Accessor/Driver combination works differently than another.

The validation rule for today is on the $container param for both the Create and Update and is as follows;

'Each element in the elements array that has the same view as the DA class must be present as a key in a Hash-ref or as an attribute in Class container. This rule is not on by default but is to be turned on only when the all_elements_present flag is true.

So to get the above in place I will need to add in that new flag here;

A very simple LRU cache with Tie::IxHash

Recently, I needed to add a simple cache to my application. In particular, I was looking for a way to memo-ize a function, and age out old entries as necessary. There's great cache modules on CPAN that do this, but I needed to accomplish it with only standard modules.

In order to create a very dumb Least-Recently-Used cache, you need a list and a hash. The hash obviously stores mapping from keys to values, and the list keeps the order of items in the most recently-used order. When an existing item is modified or retrieved, its key moves to the end of the list. When an insertion is made that would overflow the size limit of the cache, entries from the front of the list are removed. Note that the implementation below would only work for string keys (and things that are convertible to strings, like intergers, since perl hash keys are stringified), but it shouldn't be too hard to modify to handle arbitrary objects.

Better SQL tracing with DBIx::Class

I've been trying to track down some SQL issues with Tau Station and to be honest, I've never been terribly happy with the output from the DBIx::Class DBIC_TRACE or the DBI DBI_TRACE. So I have something better.

Good code style of DBIx::Custom at 2017

DBIx::Custom is good DBI wrapper to insert, update, delete, select easily and clean.

I introduce good code style of DBIx::Custom at 2017.

Connect


  my $dbi = DBIx::Custom->connect("dbi:mysql:database=dbname", 'ken', '! LFKD% $&');

Create model

It is good to create model.


  $dbi->create_model('book'); 

Execute SQL

Because model is used, insert, update, delete, select is very clean.


About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.