Inline::WebChat - mix Perl and WebChat in a Perl script
use Inline WebChat; use Data::Dumper;
my @site_links = get_site ('http://www.perl.com');
print Dumper @site_links;
__END__
__WebChat__
sub get_site {
my $site = shift; GET $site return @links; }
Inline::WebChat is a module for letting you embed WebChat scripts in your Perl scripts.
Inline::WebChat
Why would you wnat to do this? Well, Gisle Aas' WebChat is an Expect type language that fetches and manipulates web pages and their forms. For example you can do stuff like
GET http://www.perl.com EXPECT OK && /perl/ GET not_there.html EXPECT ERROR BACK BACK
... and ...
GET http://www.altavista.com EXPECT OK F q=Gisle CLICK EXPECT OK && /Gisle Aas/
Which is obviously a lot easier than hand rolling your own code with LWP and HTML::Forms ...
LWP
HTML::Forms
... which is exactly what webchat does - take your WebChat script and convert it to pure Perl. Which is why you can mix and match Perl and WebChat. Handy huh?
See webchatpp for more details on the syntax.
You never actually use Inline::WebChat directly. It is just a support module for using Inline.pm with WebChat. So the usage is always:
Inline.pm
use Inline WebChat => ...;
or
bind Inline WebChat => ...;
Apparently there are problems using Inline::Webchat with more than one subroutine.
This is a work around from Richard Clamp (bless his cotton socks) which isn't perfect but, as he so delightfully puts it "I imagine getting it to work correctly requires the ability to parse webchat augmented perl. The thought of that hurts my brain."
If anybody can figure out a better way to do it then please tell me. I need to do more testing on this.
#!perl -w use strict;
use Test::More tests => 2; use TestConfig;
use Inline 'WebChat' => <<SCRIPT;
sub is_up { GET $TestConfig::site EXPECT OK return 1
}
SCRIPT
is(is_up(), 1, "site is up");
sub will_404 { GET $TestConfig::site/four_oh_four EXPECT ERROR return 1;
is(will_404, 1, "404s $TestConfig::site/four_oh_four");
o None so far but I haven't tested it very much. Go! Hack! Break! Let me know what's wrong.
o Could do with some more examples
o I'm not happy with the whole WebChat design in general - I mean, I had to patch it to get it working with his in the first place. Hmm, maybe when I have more time.
For general information about Inline see Inline.
For more information about WebChat see webchatpp, WWW::Chat and WWW::Chat::Processor
WebChat
For information on supported languages and platforms see Inline-Support.
For information on writing your own Inline Language Support Module, see Inline-API.
Inline's mailing list is inline@perl.org
To subscribe, send email to inline-subscribe@perl.org
Simon Wistow <simon@thegestalt.org>
Copyright (c) 2001. Simon Wistow. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Inline::WebChat, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Inline::WebChat
CPAN shell
perl -MCPAN -e shell install Inline::WebChat
For more information on module installation, please visit the detailed CPAN module installation guide.