| 1 | #! perl | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Sigmund - Fully commented plugin for Comics. | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | Please read the comments in the source. | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | This plugin handles the Sigmund comics from http://www.sigmund.nl . | ||
| 17 | |||
| 18 | It is also a commented example of how to write your own plugins. | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | # All plugins fall under the Comics::Plugin hierarchy. | ||
| 23 | # | ||
| 24 | # Please choose a descriptive name for the plugin. | ||
| 25 | # | ||
| 26 | # Some examples: | ||
| 27 | # | ||
| 28 | # Comics::Plugin::9ChickweedLane | ||
| 29 | # Comics::Plugin::CalvinAndHobbes | ||
| 30 | # Comics::Plugin::FokkeEnSukke | ||
| 31 | # Comics::Plugin::LeastICouldDo | ||
| 32 | # Comics::Plugin::SMBC (Saturday Morning Breakfast Cerial) | ||
| 33 | |||
| 34 | package Comics::Plugin::Sigmund; | ||
| 35 | |||
| 36 | # Plugins inherit from a Fetcher and must set a number of package | ||
| 37 | # variables. | ||
| 38 | # | ||
| 39 | # Currently the following Fetchers are implemented: | ||
| 40 | # | ||
| 41 | # Comics::Fetcher::Direct | ||
| 42 | # | ||
| 43 | # Requires '$path' and performs a direct fetch of the | ||
| 44 | # specified URI. | ||
| 45 | # | ||
| 46 | # See Comics::Plugin::LeastICouldDo for an example. | ||
| 47 | # | ||
| 48 | # Comics::Fetcher::Single | ||
| 49 | # | ||
| 50 | # Requires '$patterm'. The fetcher fetches the main page and uses | ||
| 51 | # this pattern to find the URL of the actual image. | ||
| 52 | # | ||
| 53 | # Comics::Fetcher::GoComics | ||
| 54 | # | ||
| 55 | # A special Fetcher for comics that reside on GoComics.com. | ||
| 56 | # | ||
| 57 | # Only the starting URL '$url' is required. | ||
| 58 | # | ||
| 59 | # See Comics::Plugin::Garfield for an example. | ||
| 60 | # | ||
| 61 | # Comics::Fetcher::Cascade | ||
| 62 | # | ||
| 63 | # Requires an array '@patterns'. The fetcher fetches the main | ||
| 64 | # page and uses the first pattern to find the URL of the next | ||
| 65 | # page, applies the next pattern, and so on, until the last | ||
| 66 | # pattern yields the url of the desired image. | ||
| 67 | # | ||
| 68 | # Fetchers Direct, Single and GoComics are tiny wrappers around | ||
| 69 | # the Cascade Fetcher. It is, however, advised to always use the | ||
| 70 | # wrappers for administration purposes. | ||
| 71 | |||
| 72 | # This plugin uses the Simple Fetcher. | ||
| 73 | |||
| 74 | 1 | ▶ | use parent qw(Comics::Fetcher::Single); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 75 | |||
| 76 | 1 | our $VERSION = "1.02"; | |
| 77 | |||
| 78 | # Mandatory variables: | ||
| 79 | # | ||
| 80 | # $name : the full name of this comic, e.g. "Fokke en Sukke" | ||
| 81 | # $url : the base url of this comic | ||
| 82 | |||
| 83 | 1 | our $name = "Sigmund"; | |
| 84 | 1 | our $url = "https://sigmund.nl/"; | |
| 85 | |||
| 86 | # Optional variables: | ||
| 87 | # | ||
| 88 | # $ondemand : This plugin is initially disabled, but can be | ||
| 89 | # enabled via the command line. | ||
| 90 | # $disabled : Permanently disables this plugin. It cannot be | ||
| 91 | # re-enabled via the command line. | ||
| 92 | # Useful if a plugin doesn't work (yet/anymore), | ||
| 93 | # or the site has ceased to exist. | ||
| 94 | |||
| 95 | # Other variables depend on the Fetcher. | ||
| 96 | # | ||
| 97 | # For the Direct Fetcher: | ||
| 98 | # | ||
| 99 | # $path : the path, relative to the url, to the image | ||
| 100 | # | ||
| 101 | # For the Single Fetcher: | ||
| 102 | # | ||
| 103 | # $pattern : a pattern to locate the image URI. | ||
| 104 | # When the pattern matches it must define at least | ||
| 105 | # the following named captures: | ||
| 106 | # url : the (relative) url of the image | ||
| 107 | # image : the image name within the url | ||
| 108 | # | ||
| 109 | # Optionally it may define: | ||
| 110 | # | ||
| 111 | # title : the image title | ||
| 112 | # alt : the alternative text | ||
| 113 | # | ||
| 114 | # For the Cascade Fetcher: | ||
| 115 | # | ||
| 116 | # @patterns : an array of patterns to locate the image URI. | ||
| 117 | # | ||
| 118 | # For the GoComics Fetcher: | ||
| 119 | # | ||
| 120 | # No extra variables are needed. | ||
| 121 | # | ||
| 122 | # Notes on patterns: | ||
| 123 | # | ||
| 124 | # URLs ususally start with http:// or https://, so always use | ||
| 125 | # https?:// . | ||
| 126 | # Images are usually jpg, gif or png, so for the image use | ||
| 127 | # (?<image> ... (?:jpg|gif|png) ) . | ||
| 128 | |||
| 129 | 1 | our $pattern = | |
| 130 | qr{ <img \s+ id="strook" \s+ | ||
| 131 | src="?(?<url>https?://www.sigmund.nl/strips/(?<image>sig.+\.\w+))"? | ||
| 132 | }x; | ||
| 133 | |||
| 134 | # Important: Return the package name! | ||
| 135 | 1 | __PACKAGE__; | |