the core idea behind Complete Programming (tm)(c)

During my last post I mentioned the method of Complete Programming, which started as my knee jerk reaction to the insanities of waterfall and XP. I'm not really big on manifestos but writing down things helps to think clearly and so you might also benefit from thinking about one important principle in CP.

Perl6 - NativeCall, using the native trait correctly

I saw a lot of confusion with what should be passed to the native trait when working on binding a C function from a library using NativeCall.

One important thing to remember is Perl 6 trait are solved at compile time. This is important because every value passed to a trait take their compile time value.

use NativeCall;
my $foo = "a";
sub foo is native($foo) {*}

This will fail to compile since native does not take Any has a valid type. Even if $foo can be checked as being a Str, its compile time type is Any. Easy to check with a BEGIN block.

<Skarsnik> m: use NativeCall; my $foo = "a"; say $foo.^name
<evalable6> Skarsnik, rakudo-moar 79604a880: OUTPUT: «Str»
<Skarsnik> m: use NativeCall; my $foo = "a"; BEGIN {say $foo.^name};
<evalable6> Skarsnik, rakudo-moar 79604a880: OUTPUT: «Any»

It's actually explained in NativeCall documentation

On Troll Hugging, Hole Digging, and Improving Open Source Communities

Read this article on Rakudo.Party

While observing a recent split in a large open source community, I did some self-reflection and thought about the state of the Rakudo community that I am a part of. It involved learning of its huggable past; thinking of its undulating present; as well as looking for its brighter future.

This article is the outcome. It contains notes to myself on how to be a better human, but I hope they'll have wider appeal and can improve communities I am a part of.

Part I: Digging a Hole

A lot of organizational metaphors involve the act of climbing. You start at the base of a hill or a ladder and you start climbing. The higher you get, the more knowledge, power, and resources you attain. There's a problem with that metaphor: you're facing the backs of the people who came before you and they're not really paying attention to you.

C comments and regular expressions

C comments and regular expressions

The C programming language has two kinds of comments, ones with a start and end marker of the form /* comment */, and another one which starts off with two slashes, //, and goes to the end of the line, like Perl comments. The /* */ kind are the original kind, and the // kind were borrowed from C++.[1]

Let's suppose you need to match the original kind of C comments. A simple regex might look something like this:

qr!/\*.*\*\/!

Here we've escaped the asterisks in the comment with a backslash, \, and used exclamation marks, !, to demark the start and end of the regex, so that we don't have to escape / with a backslash.

However, C comments have the feature that they can extend over multiple lines:

/*
  Comment
*/

which means that the above regex doesn't work. The problem is that the dot, ., doesn't match new lines. If we add the s flag to the end of the regex, the match succeeds:

qr!/\*.*\*\/!s

The s flag alters . so that it matches newlines.

Check compression in web page

This module offers a way to check your web pages for correct gzip compression. It not only checks that your web page is compressed properly when required, but also checks that the web page is not accidentally compressed when not required, and that the compression actually does something useful in terms of reducing the page size. I wrote it because I couldn't find anything to do that on CPAN.

It's compatible with Test::More if you want to run the compression checks automatically.

Picking a better Markdown library for bad input

I was handling some bad Markdown input using Text::Markdown, when I saw it generate broken HTML.

I started with (bad) Markdown input " 1. z\n >" and got back HTML <p><ol>\n<li>z</p>\n\n<blockquote>\n <p></li>\n </ol></p>\n</blockquote>.

(See the incorrectly nested HTML tags, <p><ol><li></p>?)

So I tried feeding this bad Markdown to four different Perl Markdown libraries: Text::Markdown, Text::MultiMarkdown, Text::Markdown::Discount, and Markdent, to see which one would give me valid HTML.

The results?

  • Text::Markdown — invalid HTML <p><ol>\n<li>z</p>\n\n<blockquote>\n <p></li>\n </ol></p>\n</blockquote>\n

  • Text::MultiMarkdown — invalid HTML <p><ol>\n<li>z</p>\n\n<blockquote>\n <p></li>\n </ol></p>\n</blockquote>\n

  • Text::Markdown::Discount — valid HTML! <ol>\n<li> z\n\n<blockquote></blockquote></li>\n</ol>\n\n

  • Markdent — valid HTML, but doesn't generate a simple HTML fragment <!DOCTYPE html>\n<html><head><title></title></head><body><ol><li>z\n &gt;\n</li></ol></body></html>

The solution? Switch from Text::Markdown to Text::Markdown::Discount.

How to pass arguments for Mojolicious filter

Sometimes we are required to check incoming IDs not only for format, but also for existence in DB.

But different IDs we should check through different models.

This pull request tries to add this functionality. If it will be appiled you can do next:

$v->required( 'invoice_id', [ data_exists => 'Invoice' ] );
$v->required( 'order_id', [data_exists => 'Order' ] );

And the fileter:

$v->add_filter( data_exists => sub { data_exists( $app, @_ ) } );

sub data_exists {
    my( $app, $v, $name, $value, $model ) =  @_;

    my $obj =  $app->rows( $model )->find( $value )
       or return ();

    return $obj;
}

If you want your model do advanced decision about its data accessible or not you may pass current context:

$v->required( 'invoice_id', [ data_exists => $c, 'Invoice' ] );

The filter:

sub data_exists {
    my( $v, $name, $value, $c, $model ) =  @_;

    my $obj =  $c->rows( $model )->find( $value )
       or return ();

    return $obj;
}

And somewhere in the model:

sub rows {
    my( $c, $table_name ) = @_;
    ...
    $c->db->relation_ship( $table_name )->search({ user_id => $c->uid });
}

So after validation you are guarantied to have objects which are allowed to access only for current user.

And there is no way to access other objects the user do not own

Perl 5 Porters Mailing List Summary: August 22nd-28th

Hey everyone,

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

Enjoy!

Swiss Perl Workshop 2017 - Videos

We have uploaded videos from this year's workshop to YouTube: Swiss Perl Workshop on YouTube.

Note that we didn't record all talks as some were given at TPC and will be of much better quality from them. Also we didn't record the workshops, nor the lightning talks. Still, we have some exclusive content, so have a look.

You're invited: Community Bug SQUASHathon

Rakudo and other repositories in perl6 GitHub org have plenty of open bug tickets. We decided it would be neat to give them an extra push with concentrated effort, which is why we'd like to organize a monthly, 1-day virtual event where we pick a repository and everyone works on open tickets in that repository.

The day will be first Saturday of every month. This month we'll be hacking on the Issues of github.com/perl6/doc repository.

Whether you're a seasoned Rakudo developer or just starting out, join us this Saturday in #perl6 on irc.freenode.net chat channel (no specific time) and contribute! If you'd like to simply hang out, you're welcome too, we love company!

See also: our SQUASHathon Wiki or talk to a human about this.

New ways to include images in CPAN modules

The latest release of Test::podimage, version 0.05, shows a few interesting experimental ways to include images in CPAN modules.

It seems there is a way to show image files from the distribution on metacpan by using a leading slash, which I'd never heard of until now. There's also a new "=for image" tag. Oddly enough, although this was proposed five days ago, the CPAN grep search site tells us that this tag actually appears in some CPAN modules such as this one from 2010, although the above don't actually display on metacpan, perhaps because there is no leading slash in the image name.

A data URL can also be used.

Most of the image formats don't work on search.cpan.org.

Split a .pm into a .pod and a .pm

I searched on CPAN but was unable to find a way to split a .pm into a .pod and a .pm, so I made this script:

https://www.lemoda.net/perl/split-pod-from-pm/index.html

It's proved quite handy so far. Recently I took over maintenance of an old module called Net::IPv6Addr as part of the CPAN day. Today I upgraded the documentation a little so that the synopsis example is machine readable:

https://metacpan.org/source/BKB/Net-IPv6Addr-0.7/examples/synopsis.pl

https://metacpan.org/pod/Net::IPv6Addr#SYNOPSIS

Since most people probably don't read the documentation beyond the synopsis, I think it's important to make sure that the code example in the synopsis actually works. There are quite a few modules on CPAN where the synopsis code doesn't work. In the case of Net::IPv6Addr, I even have a test that the synopsis example works:

https://github.com/benkasminbullock/net-ipv6addr/blob/master/t/synopsis.t
https://metacpan.org/source/BKB/Net-IPv6Addr-0.7/t/synopsis.t

Script to update some modules

I have some modules which I need to periodically install on a web server, and cannot use cpan or cpanm to do this. One of the problems with this is that the local copies I made of the modules sometimes get out of date with the CPAN version. The following script updates the local copies of the modules. This uses make_regex from Convert::Moji to make a matching regex for a list of modules, but you can use list2re from Data::Munge in place of that.

Promises promises ...

Problems with concurrency, a post from the hard reality.

This worries me a bit I must admit; a few years ago, before the official release of P6, I tried my hand at concurrent programming in rakudo and it was so broken that i simply shelved P6 for over a year, it was simply not ready for a lambda dev like me. I would have loved to be in the trenches but I did not have the time to fight with core dumps.

As the speed of P6 is not stellar, I believe many of us, lambdas, will try to run things in parallel, it's also fun, to make them more attractive. The concurrency mechanism in P6 look good on paper, good enough so I can find myself dreaming of throwing in a few keywords in places I think concurrency would make a difference.

There is a nice silver lining to this one, It took a very short time before a lead developer answered me. I believe his answers may be interesting to read.

A description of the problems I encountered is here: gist

Perl in Japan

We recently did an interview with Daisuke Maki on the Perl community in Japan.

This is what came out of it - http://blog.builtinperl.com/post/perl-in-japan.

Have a look/read.

Perl 5 Porters Mailing List Summary: August 15th-21st

Hey everyone,

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

Enjoy!

Trying out AWK in Java with Perlito5

I’ve got this example “awk” script:

$ cat x.awk 
BEGIN { print "Month Crates"
    print "----- ------" }
    { print $1, " ", $2 }

we can convert AWK to Perl with “a2p”:

$ a2p x.awk > x.pl

now create a test input file:

$ cat > x.txt
a b
d e
1 2

and try it out in Perl5-Java:

$ java -jar perlito5.jar x.pl x.txt 
Month Crates
----- ------
a     b
d     e
1     2

yay!

How the RPi::WiringPi distribution is tested

So I'm gearing up to write a "Howto Raspberry Pi with Perl" multi-chapter tutorial, and as I finalize a few last things, I thought I'd put together how all of the software is laid out and is continuously tested.

The RPi::WiringPi distribution is essentially a class that provides access to external sub distributions, and provides several benefits such as maintaining a registry of in-use GPIO pins, and ensuring your Pi is cleaned up back to default on exit, or if an error or signal is caught. The sub modules do none of those things.

I use the automation and dispatching capabilities of my Test::BrewBuild software to handle the test management. This software runs your unit tests on any/all Perlbrew and/or Berrybrew installed instances, with the ability to dispatch your test requests over the network to remote machines. I'm not getting into those details, just know I use the bbtester binary to listen for test requests, and the bbdispatch binary to send them, both on the same Raspberry Pi hardware.

Plan for perldoc 4.0

At TPC in Amsterdam I gave 2 lightning talks under the title perldoc -O. It was a questionary for the attendance which should give me some orientation which feature to prioritize or how to modify them best. I also spoke and mailed with all people I deemed relevant and want now to lay out the feature set I want to achieve with the rewrite.

SPVM progress in 2017/08/17(SPVM have static typing and fast and easy to call function)

SPVM project is improved day by day. SPVM is the project which provide static type data structure to Perl, and improve the performance of numeric and array operation.

I start to write SPVM specification. Most of all are Perl syntax.

Latest change is the following.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.