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

NAME

MojoX::ValidateHeadLinks - Ensure CSS and JS links in web pages point to real files

Synopsis

        shell> validate.head.links.pl -h
        shell> validate.head.links.pl -d /run/shm/html -u http://127.0.0.1/index.html

This program calls the "run()" method, which returns the number of errors found. Various logging options, discussed under "Constructor and initialization" and in the "FAQ", control the amount of output. Nothing is printed by default.

On my machine, /run/shm/ is the directory used to access the Debian built-in RAM disk, and /run/shm/html/ is my web server document root directory.

Since this script -validate.head.links.pl - ships in the bin/ directory, it is installed somewhere along your executable search path when the module is installed.

Description

MojoX::ValidateHeadLinks is a pure Perl module.

It does no more than this:

o Downloads and parses a web page using Mojo::UserAgent

Hence the -url parameter to validate.head.links.pl.

Hence the -directory parameter to validate.head.links.pl.

It handles the '@import' option used in some CSS links.

Distributions

This module is available as a Unix-style distro (*.tgz).

See http://savage.net.au/Perl-modules.html for details.

See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing.

Constructor and initialization

new(...) returns an object of type MojoX::ValidateHeadLinks.

This is the class contructor.

Usage: MojoX::ValidateHeadLinks -> new().

This method takes a hashref of options.

Call new() as new({option_1 => value_1, option_2 => value_2, ...}).

Available options (which are also methods):

o doc_root => $dir_name

Use this to specify the doc root directory of your web server. This option is mandatory.

Default: ''.

o maxlevel => $logOption1

This option affects Log::Handler.

See the Log::Handler::Levels docs, and the "FAQ".

Default: 'notice'. This means nothing is printed.

For maximum details in the printed report, try:

        MojoX::ValidateHeadLinks -> new(doc_root => $d, maxlevel => 'debug', url => $u) -> run;
o minlevel => $logOption2

This option affects Log::Handler.

See the Log::Handler::Levels docs.

Default: 'error'.

No lower levels are used.

o url => $url

Use this to specify the URL of the web page to be checked.

Default: ''.

If the string supplied does not start with 'http', then 'http://' is prefixed to $url automatically.

Methods

doc_root([$dir_name])

Here, the [] indicate an optional parameter.

Get or set the name of your web server doc root directory.

log($level => $message)

Log the string $message at log level $level.

The logger object is of class Log::Handler.

maxlevel([$string])

Here, the [] indicate an optional parameter.

Get or set the value used by the logger object.

For more details in the printed report, try:

        MojoX::ValidateHeadLinks -> new(doc_root => $d, maxlevel => 'debug', url => $u) -> run;

'maxlevel' is a parameter to "new()". See "Constructor and Initialization", and the "FAQ", for details.

minlevel([$string])

Here, the [] indicate an optional parameter.

Get or set the value used by the logger object.

'minlevel' is a parameter to "new()". See "Constructor and Initialization" for details.

new()

See "Constructor and Initialization" for details on the parameters accepted by "new()".

quit($message)

Logs $message at log level error, and then dies.

Errors can arise in these situations:

o doc_root has no value during the call to "run()"
o url has no value during the call to "run()"

run()

Does all the work.

Returns the number of errors detected, so 0 is good and N > 0 is bad.

url([$url])

Here, the [] indicate an optional parameter.

Get or set the URL of the web page your wish to check.

FAQ

How does bin/validate.head.links.pl differ from linkcheck.pl?

linkcheck.pl does not check that links to non-HTML resources (CSS, JS) point to real files.

How does the -maxlevel parameter affect the output?

In these examples, $DR stands for the /run/shm/html/ directory, the doc root of my web server.

Output from a real run, where my dev web site is the same as my real web site (so -d $DR works):

        shell> validate.head.links.pl -d $DR -url http://savage.net.au/Novels-etc.html -max debug

        URL: http://savage.net.au/Novels-etc.html
         Import: /run/shm/html/assets/js/DataTables-1.9.4/media/css/demo_page.css
         Import: /run/shm/html/assets/js/DataTables-1.9.4/media/css/demo_table.css
           Link: /run/shm/html/assets/css/local/default.css
         Script: /run/shm/html/assets/js/DataTables-1.9.4/media/js/jquery.js
         Script: /run/shm/html/assets/js/DataTables-1.9.4/media/js/jquery.dataTables.min.js
        Imports: 2. Errors: 0
          Links: 1. Errors: 0
        Scripts: 2. Errors: 0

        shell> validate.head.links.pl -d $DR -url http://savage.net.au/Novels-etc.html -max info

        Imports: 2. Errors: 0
          Links: 1. Errors: 0
        Scripts: 2. Errors: 0

        shell> validate.head.links.pl -d $DR -url http://savage.net.au/Novels-etc.html -max error

        (No output)

        shell> echo $?
        0

Repository

https://github.com/ronsavage/MojoX-ValidateHeadLinks

Support

Email the author, or log a bug on RT:

https://rt.cpan.org/Public/Dist/Display.html?Name=MojoX::ValidateHeadLinks.

Author

MojoX::ValidateHeadLinks was written by Ron Savage <ron@savage.net.au> in 2012.

Home page: http://savage.net.au/index.html.

Copyright

Australian copyright (c) 2012, Ron Savage.

        All Programs of mine are 'OSI Certified Open Source Software';
        you can redistribute them and/or modify them under the terms of
        The Artistic License, a copy of which is available at:
        http://www.opensource.org/licenses/index.html