
  7   Oˆl–ßi~”ên-jq@ãoÜªbÑ¿�þY�ÖÖq²>ÛÎ†G@@?é„bèÃæ ;u    O=head1 NAME

perlfaq9 - Web, Email and Networking

=head1 VERSION

version 5.20210520

=head1 DESCRIPTION

This section deals with questions related to running web sites,
sending and receiving email as well as general networking.

=head2 Should I use a web framework?

Yes. If you are building a web site with any level of interactivity
(forms / users / databases), you
will want to use a framework to make handling requests
and responses easier.

If there is no interactivity then you may still want
to look at using something like L<Template Toolkit|https://metacpan.org/module/Template>
or L<Plack::Middleware::TemplateToolkit>
so maintenance of your HTML files (and other assets) is easier.

=head2 Which web framework should I use?
X<framework> X<CGI.pm> X<CGI> X<Catalyst> X<Dancer>

There is no simple answer to this question. Perl frameworks can run everything
from basic file servers and small scale intranets to massive multinational
multilingual websites that are the core to international businesses.

Below is a list of a few frameworks with comments which might help you in
making a decision, depending on your specific requirements. Start by reading
the docs, then ask questions on the relevant mailing list or IRC channel.

=over 4

=item L<Catalyst>

Strongly object-oriented and fully-featured with a long development history and
a large community and addon ecosystem. It is excellent for large and complex
applications, where you have full control over the server.

=item L<Dancer2>

Free of legacy weight, providing a lightweight and easy to learn API.
Has a growing addon ecosystem. It is best used for smaller projects and
very easy to learn for beginners.

=item L<Mojolicious>

Self-contained and powerful for both small and larger projects,
with a focus on HTML5 and real-time web technologies such as WebSockets.

=item L<Web::Simple>

Strongly object-oriented and minimal, built for speed and intended
as a toolkit for building micro web apps, custom frameworks or for tieing
together existing Plack-compatible web applications with one central dispatcher.

=back

All of these interact with or use L<Plack> which is worth understanding
the basics of when building a website in Perl (there is a lot of useful
L<Plack::Middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>).

=head2 What is Plack and PSGI?

L<PSGI> is the Perl Web Server Gateway Interface Specification, it is
a standard that many Perl web frameworks use, you should not need to
understand it to build a web site, the part you might want to use is L<Plack>.

L<Plack> is a set of tools for using the PSGI stack. It contains
L<middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>
components, a reference server and utilities for Web application frameworks.
Plack is like Ruby's Rack or Python's Paste for WSGI.

You could build a web site using L<Plack> and your own code,
but for anything other than a very basic web site, using a web framework
(that uses L<https://plackperl.org>) is a better option.

=head2 How do I remove HTML from a string?

Use L<HTML::Strip>, or L<HTML::FormatText> which not only removes HTML
but also attempts to do a little simple formatting of the resulting
plain text.

=head2 How do I extract URLs?

L<HTML::SimpleLinkExtor> will extract URLs from HTML, it handles anchors,
images, objects, frames, and many other tags that can contain a URL.
If you need anything more complex, you can create your own subclass of
L<HTML::LinkExtor> or L<HTML::Parser>. You might even use
L<HTML::SimpleLinkExtor> as an example for something specifically
suited to your needs.

You can use L<URI::Find> or L<URL::Search> to extract URLs from an
arbitrary text document.

=head2 How do I fetch an HTML file?

(contributed by brian d foy)

The core L<HTTP::Tiny> module can fetch web resources and give their
content back to you as a string:

    use HTTP::Tiny;

    my $ua = HTTP::Tiny->new;
    my $html = $ua->get( "http://www.example.com/index.html" )->{content};

It can also store the reso