Categories
Javascript Perl

Doing common things for Perl developers on Javascript (II)

From Perl to Javascript relearning.

Perl allows us to bless any reference into any being an object of any class, this is not a good practice always, but can become handy on corner cases, here is how is done in Perl:

sub bless_into_class {
    my $class = shift;
    bless {}, $class;
}
my $object = bless_into_class( 'MY::Class' );

And the JS equivalent:

function create_object_of_class(input_class) {
    return Object.create(input_class.prototype);
}
let new_object = create_object_of_class(my_class);

Categories
Javascript Perl

Doing common things for Perl developers on Javascript (I)

From Perl to Javascript relearning.

It is common in Perl using an array as the arguments of a function, this is the useful default behaviour on Perl and I found myself not being able to do it so I searched it and I found how to do it.

This is the Perl code I wanted to emulate.

use strict;
use warnings;

use feature 'say';

sub a {
    my ($arg1, $arg2) = @_;
    say "$arg1 $arg2";
}

my @a = ('arg1', 'arg2');
a(@a);

And this is the equivalent Javascript code using .apply a prototype function for implementors of Function class.

"use strict";

function a(a, b) {
    console.log(`${a} ${b}`);
}

let a_array = [ 'arg1', 'arg2' ];

// The first argument is null because it sends the value of this.
// If you are doing this to a object it probably should be different
a.apply(null, a_array);

Categories
C Docker Javascript Peertube-dl Perl XS

What is Peertube-dl?

Peertube-dl aims to be a alternative to youtube-dl written in Perl providing a library, a cli utility and a webpage.

I am currently developing that project, I licensed it under the AGPLv3, a Free Software license.

It provides a Dockerfile which allows you to run the program in a container.

I hope you find it useful, beware it is provided to you without any warranty, but I will be happy to help you with any issues you find on https://gitea.sergiotarxz.freemyip.com/sergiotarxz/Peertube-dl/issues