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