The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Inline::WebChat - mix Perl and WebChat in a Perl script

SYNOPSIS

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;
}

DESCRIPTION

Inline::WebChat is a module for letting you embed WebChat scripts in your Perl scripts.

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 ...

... 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.

USAGE

You never actually use Inline::WebChat directly. It is just a support module for using Inline.pm with WebChat. So the usage is always:

    use Inline WebChat => ...;

or

    bind Inline WebChat => ...;

USING MORE THAN ONE SUBROUTINE / USING THE MODULE WITH Test::More

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");

use Inline 'WebChat' => <<SCRIPT;

sub will_404 { GET $TestConfig::site/four_oh_four EXPECT ERROR return 1;

}

SCRIPT

is(will_404, 1, "404s $TestConfig::site/four_oh_four");

__END__

BUGS AND DEFICIENCIES

  • 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.

SEE ALSO

For general information about Inline see Inline.

For more information about WebChat see webchatpp, WWW::Chat and WWW::Chat::Processor

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

AUTHOR

Simon Wistow <simon@thegestalt.org>

COPYRIGHT

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