http://qs1969.pair.com?node_id=944371

In this walkthrough, i'll show you how to write a simple GTK3 Webkit based browser that turns a webpage into a "native application". Apple Users probably would call it an App.

Fixing MakeMaker

First of all, If you are - like me - using any Ubuntu x64 derivate with ActivePerl 5.14, you're in for quite a ride. Mostly, because ExtUtils::MakeMaker wont find most libraries. This is easy to fix if you know how (and a bit risky too, since you are disabling checks). These checks in MakeMaker try to make sure you have the required libraries but wont find them even if you do have them.

So, find the file Kid.pm in */lib/ExtUtils/Liblist and find the following lines (somewhere around line 170 in my MakeMaker version):

} else { warn "$thislib not found in $thispth\n" if $verbose; next; } warn "'-l$thislib' found at $fullname\n" if $verbose; push @libs, $fullname unless $libs_seen{$fullname}++; $found++; $found_lib++; # Now update library lists

We'll disabling using the "results" of this checks, just comment out four lines:

} else { #warn "$thislib not found in $thispth\n" if $verbose; #next; } #warn "'-l$thislib' found at $fullname\n" if $verbose; #push @libs, $fullname unless $libs_seen{$fullname}++; $found++; $found_lib++; # Now update library lists

UPDATE: A nicer workaround of course is to check for environment variables. Let's say, if MM_DISABLE_LIBCHECKS is set to a nonzero value, override the broken checks:

} else { if(!defined($ENV{MM_DISABLE_LIBCHECKS}) || $ENV{MM_DIS +ABLE_LIBCHECKS} == 0) { warn "$thislib not found in $thispth\n" if $verbos +e; next; } } if(!defined($ENV{MM_DISABLE_LIBCHECKS}) || $ENV{MM_DISABLE +_LIBCHECKS} == 0) { warn "'-l$thislib' found at $fullname\n" if $verbose; push @libs, $fullname unless $libs_seen{$fullname}++; } $found++; $found_lib++; # Now update library lists

So, running Makefile.PL like this should do the trick:
MM_DISABLE_LIBCHECKS=1 perl Makefile.PL
Of course, this also should also work when calling any CPAN script (untested but plausible).
END-OF-UPDATE

This should do it. Since (most) Makefile.PL's use checks with "pkg-config" in addition to internal MakeMaker checks anyway, you should still see all missing dependencies from your operating system.

Installing the dependencies

You got a lot of dependencies for the module we are going to use, which is Gtk3::WebKit. Honestly, i didn't write those down - and i didn't do a clean install anyway, so i leave out the details. Mostly, you'll hunt for obscure "*-dev" packages in apt-get/synaptic. (If someone is kind enough to reply with a list of all the required packages, i'll gladly update this post).

The one, most obscure of the library packages is certainly libgirepository1.0-dev. That should pull in many of the required packages.

Writing the Browser

Without further delay, let's state some of the requirements for our project:

  • Custom Useragent string
  • Disable right-click menu
  • Call it the "PerlMonks Native Client"
  • No need for tabbed browsing (it's an "App")
  • No navigation elements (no way for a "back" button)

For the last two requirements, the only thing we have to do is not implementing those features. So, let's forget about them alltogether.

For the first two, we can just set the correct properties of the webkit element in our Gtk3 window. No big deal. For the third requirement, we set the Window title and we're done, too.

So, let's get right down to the code:

#!/usr/bin/env perl =head1 NAME gtk3_browser.pl - The PerlMonks Browser =head1 SYNOPSIS browser.pl [URL] Simple usage: browser.pl http://search.cpan.org/ =head1 DESCRIPTION Display a web page as "Native Application". =cut use strict; use warnings; use Gtk3 -init; use Gtk3::WebKit; sub main { my ($url) = shift @ARGV || 'http://www.perlmonks.org'; my $window = Gtk3::Window->new('toplevel'); $window->set_default_size(800, 600); $window->signal_connect(destroy => sub { Gtk3->main_quit() }); $window->set_title("PerlMonks Native Client"); # Create a WebKit widget my $view = Gtk3::WebKit::WebView->new(); my $settings = $view->get_settings(); $settings->set_property("user-agent", 'PerlMonks/1.0'); $settings->set_property("enable-default-context-menu", 0); # Load a page $view->load_uri($url); # Pack the widgets together my $scrolls = Gtk3::ScrolledWindow->new(); $scrolls->add($view); $window->add($scrolls); $window->show_all(); Gtk3->main(); return 0; } exit main() unless caller;

As you can see, no big deal, after you actually fought the battles against MakeMaker and your Distributions clearly confusing package managment.

All we do here is open a Gtk3 window, add a WebKit widget with some custom settings and pack it into the main window with some attached scrollbars. Then we call the Gtk3 mainloop and we got a nice, one-window one-tab browser that simulates a native application.

BREW /very/strong/coffee HTTP/1.1
Host: goodmorning.example.com

418 I'm a teapot

Replies are listed 'Best First'.
Re: Turn a Website into a native application
by Anonymous Monk on Dec 20, 2011 at 11:35 UTC

    Fixing MakeMaker

    Please forward upstream, it appears they haven't thought of that solution https://rt.cpan.org/Public/Bug/Display.html?id=69318 # Bug #69318 for ExtUtils-MakeMaker: EU:MM rejects necessary link library

    The temporary kludge is to edit Makefile.PL and prefix :nosearch

      The temporary kludge is to edit Makefile.PL and prefix :nosearch

      Seems it isn't anymore. Current version outputs something along the line ":nosearch" is not a known keyword or something like that.

      Update: Please forward upstream, it appears they haven't thought of that solution

      Been there, done that, got the T-Shirt.

      BREW /very/strong/coffee HTTP/1.1
      Host: goodmorning.example.com
      
      418 I'm a teapot

        Seems it isn't anymore. Current version outputs something along the line ":nosearch" is not a known keyword or something like that.

        Um, prefix it to LIBS, for ExtUtils::Liblist , as my link explains

Re: Turn a Website into a native application
by davido (Cardinal) on Dec 20, 2011 at 17:52 UTC

    First of all, If you are - like me - using any Ubuntu x64 derivate with ActivePerl 5.14, you're in for quite a ride. Mostly, because ExtUtils::MakeMaker wont find most libraries.

    Thank you, thank you...! This may help explain why a module I'm maintaining keeps failing about 2 of 50 smoke tests with a report that one of the dependencies couldn't be found; a dependency that is listed as installed at the dependency summary at the end of the test.


    Dave

      To be clear so we speak of the same thing: The MakeMaker patch here only affects searching system libraries, e.g. the LIBS array in Makefile.PL.

      Everything else (available Perl modules) is not affected.

      Due to some small problems, incompatibilities, broken binary packages (operating system, ActivePerl) it is actually possible that an XS module will be installed that can not find a system library at runtime.

      Another common problem i encounter are these f...ing optional dependencies of some modules. Take the unholy XML parsing mess for example: XML::Simple may be available... that doesn't mean it will actually work, because someone has uninstalled or broken-installed all the actual parser modules - or just removed libexpat from his/her system. Or somehow even managed to install XML::Simple without any available parser (shouldn't happen anymore).

      Or take DBI. This thing is very flexible. Let's say you want to use DBD::Oracle. The only way to make sure it really works is to actually use it, e.g. connect to the Oracle database you want to work with. Even if DBD::Oracle and the binary oracle client library is available and everything loads correctly (=the lib didn't change since you compiled your XS against it) it doesn't actually mean it will work. The Oracle server might have been upgraded and is now (partly) incompatible with whatever OCI version your client is using.

      So, a few failed tests on a small number of computers - especially for complex modules - shouldn't be alarming. Best way to figure things out is probably trying to contact the persons that submitted the FAIL reports and work with them to find the problem.

      If i remember correctly: The cpantesters reports basically submit all the output that is generated by the test run. So, if a test fails on certain dependencies, your tests could actually check if it can find the libraries/modules/packages/whatever on the system in question (calling "locate" on Linux/Unix comes to mind) and output the results as warnings. This warnings in turn won't break your tests but will give you more information to work with.

      BREW /very/strong/coffee HTTP/1.1
      Host: goodmorning.example.com
      
      418 I'm a teapot
Re: Turn a Website into a native application
by cavac (Parson) on Dec 20, 2011 at 14:15 UTC
    Update: Better solution for fixing MakeMaker; updated in original post.
    BREW /very/strong/coffee HTTP/1.1
    Host: goodmorning.example.com
    
    418 I'm a teapot
Re: Turn a Website into a native application
by dk (Chaplain) on Dec 23, 2011 at 22:50 UTC
    does "LIBS => ':nosearch'" work for you? It fools MakeMaker into believing that libs are there. ( see perldoc ExtUtils::Liblist for more )

      The purpose of OPs patch it to avoid having to modify each and every Makefile.PL

      :nosearch is a documented "feature" of ExtUtils::Liblist

      Tried it but failed. Maybe i did something wrong.

      It also has the problem that - even when it works - it would still require to "fix" the Makefile.PL on each and everyone of the modules i want to install. At least everyone that requires at least one external library. Thats not very useful.

      That problem can waste a lot of time when i upgrade my ActivePerl or install a new server. So i just install my own "fake-fixed" version of MakeMaker and be done with it.

      BREW /very/strong/coffee HTTP/1.1
      Host: goodmorning.example.com
      
      418 I'm a teapot