| 1 | package Plack::Middleware::Favicon_Simple; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use parent qw{Plack::Middleware}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.01'; | |||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Plack::Middleware::Favicon_Simple - Perl Plack Middleware to provide favicon | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | use Plack::Builder qw{builder mount enable}; | ||||||||||
| 15 | builder { | ||||||||||
| 16 | enable "Plack::Middleware::Favicon_Simple"; | ||||||||||
| 17 | $app; | ||||||||||
| 18 | }; | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | Browsers request /favicon.ico automatically. This Plack Middleware returns a favicon.ico file so that browsers do not get 404 HTTP codes. | ||||||||||
| 23 | |||||||||||
| 24 | =head1 METHODS | ||||||||||
| 25 | |||||||||||
| 26 | =head2 call | ||||||||||
| 27 | |||||||||||
| 28 | Middleware wrapper method. | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub call { | ||||||||
|
Subroutine
call: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 33 | 0 | my $self = shift; | |||||||||
| 34 | 0 | my $env = shift; | |||||||||
| 35 | 0 | ▶ | if ($env->{'PATH_INFO'} eq '/favicon.ico') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | return [200, ['Content-Type' => 'image/x-icon'], [$self->favicon]]; | |||||||||
| 37 | } else { | ||||||||||
| 38 | 0 | return $self->app->($env); | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | =head2 favicon | ||||||||||
| 43 | |||||||||||
| 44 | Sets the favicon from a binary source. | ||||||||||
| 45 | |||||||||||
| 46 | builder { | ||||||||||
| 47 | enable "Plack::Middleware::Favicon_Simple", favicon=>$binary_blob; | ||||||||||
| 48 | $app; | ||||||||||
| 49 | }; | ||||||||||
| 50 | |||||||||||
| 51 | Default is a blank icon. | ||||||||||
| 52 | |||||||||||
| 53 | =cut | ||||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | sub favicon { | ||||||||
|
Subroutine
favicon: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||
| 56 | 1 | my $self = shift; | |||||||||
| 57 | 1 | ▶ | $self->{'favicon'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 1 | ▶ | unless (defined $self->{'favicon'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | #default: blank favicon.ico | ||||||||||
| 60 | 0 | require MIME::Base64; | |||||||||
| 61 | 0 | $self->{'favicon'} = MIME::Base64::decode(' | |||||||||
| 62 | AAABAAEAEBACAAEAAQCwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAgAAAAAAAAA | ||||||||||
| 63 | AAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | ||||||||||
| 64 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD//w | ||||||||||
| 65 | AA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA | ||||||||||
| 66 | '); | ||||||||||
| 67 | } | ||||||||||
| 68 | 1 | return $self->{'favicon'}; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | =head1 SEE ALSO | ||||||||||
| 72 | |||||||||||
| 73 | L<Plack::Middleware>, L<Plack::Middleware::Favicon> | ||||||||||
| 74 | |||||||||||
| 75 | =head1 AUTHOR | ||||||||||
| 76 | |||||||||||
| 77 | Michael R. Davis | ||||||||||
| 78 | |||||||||||
| 79 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 80 | |||||||||||
| 81 | MIT License | ||||||||||
| 82 | |||||||||||
| 83 | Copyright (c) 2022 Michael R. Davis | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | 1 | 1; | |||||||||