Start with Perl introspection from C API (original) (raw)

Hi, I would love to add more C API functions to HTTP::Soup Perl module.

Currently, the decoding and encoding functions are missing. I need them for a CGI script.

As looking at the perl module, I can’t find any .gir files:

Just recognized does something using gir in the meson build file.

I am missing the link between libsoup and HTTP::Soup, how is it organized? Where is the typelib provided and where are the gir files?

https://wiki.gnome.org/Projects/GTK-Perl/Introspection


by Joël

jkraehemann (Joël Krähemann) March 19, 2019, 7:21pm 2

Update, found the XS tutorial:

https://perldoc.perl.org/perlxstut.html

… and the XS documentation:

https://perldoc.perl.org/perlxs.html

HTTP::Soup seems to use it.

ebassi (Emmanuele Bassi) March 20, 2019, 11:54am 3

The HTTP::Soup bindings are statically generated, and fairly out of date.

You should use Glib::Object::Introspection instead, and generate them dynamically from the introspection data. For instance, Glib::IO and Gtk3 use introspection and pure Perl to paper over the less Perl-y bits of the C API.

Using introspection has the added benefit that you can extract the documentation from the introspection data; Glib::Object::Introspection installs a small documentation viewer for that.

jkraehemann (Joël Krähemann) March 21, 2019, 7:48am 4

Just recognized, all I need is to apt-get install libsoup2.4-dev gir1.2-soup-2.4 and create a file with the content:

package HTTP::Soup;

use Glib::Object::Introspection;

sub import {
  Glib::Object::Introspection->setup(basename => $BASENAME,
                                     version => $VERSION,
                                     package => $PACKAGE);
}
 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>B</mi><mi>A</mi><mi>S</mi><mi>E</mi><mi>N</mi><mi>A</mi><mi>M</mi><mi>E</mi><msup><mo>=</mo><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mi>S</mi><mi>o</mi><mi>u</mi><msup><mi>p</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo separator="true">;</mo></mrow><annotation encoding="application/x-tex">BASENAME = &#x27;Soup&#x27;; </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7519em;"></span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="mord mathnormal">A</span><span class="mord mathnormal" style="margin-right:0.10903em;">SEN</span><span class="mord mathnormal">A</span><span class="mord mathnormal" style="margin-right:0.05764em;">ME</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel"><span class="mrel">=</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.9463em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">o</span><span class="mord mathnormal">u</span><span class="mord"><span class="mord mathnormal">p</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7519em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">′</span></span></span></span></span></span></span></span></span><span class="mpunct">;</span></span></span></span>VERSION = '2.4'; $PACKAGE = 'HTTP::Soup';

potyl (Emmanuel Rodriguez) March 26, 2019, 2:04am 5

The HTTP::Soup bindings are statically generated, and fairly out of date.

The HTTP::Soup bindings are generated with Glib::Object::Introspection [1]. At the time the gir definition files were far from being complete so the bindings had to resort to XS in order to provide the missing pieces.

I haven’t checked if the gir files are now providing the missing functions and methods.

[1] lib/HTTP/Soup.pm - metacpan.org

system (system) Closed March 31, 2019, 2:04am 6

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.