Comics

 view release on metacpan or  search on metacpan

lib/Comics.pm  view on Meta::CPAN

    }

    unless ( $rebuild ) {
	# Run the plugins to fetch new images.
	run_plugins();

	# Save the state.
	save_state();
    }

    # Gather the HTML fragments into a single index.html.
    build();

    # Show processing statistics.
    statistics();
}

################ State subroutines ################

use JSON;

lib/Comics.pm  view on Meta::CPAN

	    push( @{ $stats->{fail} },
		  [ $comic->{name}, $comic->{state}->{fail} ] );
	}
    }
}

################ Index subroutines ################

sub build {

    # Change to the spooldir and collect all HTML fragments.
    chdir($spooldir) or die("$spooldir: $!\n");
    opendir( my $dir, "." );
    my @files = grep { /^[^._].+(?<!index)\.(?:html)$/ } readdir($dir);
    close($dir);
    warn("Number of images = ", scalar(@files), "\n") if $debug;
    $stats->{tally} = $stats->{uptodate} = @files if $rebuild;

    # Sort the fragments on last modification date.
    @files =
      map { $_->[0] }
	sort { $b->[1] <=> $a->[1] }
	  grep { $force || ! $state->{comics}->{$_->[2]}->{disabled} }
	    map { ( my $t = $_ ) =~ s/\.\w+$//;
		  [ $_, (stat($_))[9], $t  ] }
	      @files;

    if ( $debug > 1 ) {
	warn("Images (sorted):\n");

lib/Comics/Fetcher/Base.pm  view on Meta::CPAN

    my ( $self, $image, $data ) = @_;
    my $f = $self->spoolfile($image);
    open( my $fd, ">:raw", $f );
    print $fd $$data;
    close($fd) or warn("$f: $!\n");
    ::debug("Wrote: $f");
}

=head2 save_html($html)

Generates and saves the HTML fragment for this comic to the spooldir,
using I<html> as the name for the file.

See also: B<spoolfile>.

=cut

sub save_html {
    my ( $self, $html, $data ) = @_;
    my $f = $self->spoolfile($html);
    open( my $fd, ">:utf8", $f );
    print $fd ( $data // $self->html );
    close($fd) or warn("$f: $!\n");
    ::debug("Wrote: $f");
}

=head2 load_html($html)

Loads the HTML fragment for this comic from the spooldir,

See also: B<spoolfile>.

=cut

sub load_html {
    my ( $self, $html ) = @_;
    my $f = $self->spoolfile($html);
    my $opts = { split => 0, fail => "soft" };
    my $data = loadlines( $f, $opts );

lib/Comics/Plugin/Base.pm  view on Meta::CPAN


=item url

The url of this comic's home page.

=item tag

A short identifier for this comic. This will be automatically provided
if not specified.

The tag is used to generate file names for images and HTML fragments.

=back

=cut

sub register {
    my ( $pkg, $init ) = @_;

    # API 1.0 - change to new naming.
    $init->{pattern}  = delete $init->{pat};

lib/Comics/Plugin/Base.pm  view on Meta::CPAN

    bless $self, $pkg;
    $self->{tag} ||= $self->tag_from_package;

    return $self;
}

=head1 METHODS

=head2 html

Generates an HTML fragment for a fetched image.

=cut

sub html {
    my ( $self ) = @_;
    my $state = $self->{state};

    my $w = $state->{c_width};
    my $h = $state->{c_height};
    if ( $h && $w ) {



( run in 0.942 second using v1.01-cache-2.11-cpan-364913b4093 )