| 1 | package Dist::Zilla::Plugin::Pod::Spiffy; | ||||||||||
| 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 | 1 | our $VERSION = '1.001008'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | with qw/Dist::Zilla::Role::FileMunger/; | |||||||||
| 10 | 1 | ▶ | use Acme::CPANAuthors; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use namespace::autoclean -also => qr/^__/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | sub munge_file { | ||||||||
|
Subroutine
munge_file: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 14 | 0 | my ($self, $file) = @_; | |||||||||
| 15 | 0 | ▶ | return unless $file->name =~ /\.(?:p[lm]|t)$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | my $content = $file->content; | |||||||||
| 18 | 0 | $content =~ s/ | |||||||||
| 19 | ^=for\s+ pod_spiffy \s+ (?<args>.+?) (?=\n\n) | ||||||||||
| 20 | | | ||||||||||
| 21 | ^=begin\s+ pod_spiffy \s+ (?<args>.+?) ^=end\s+ pod_spiffy \s+\n | ||||||||||
| 22 | 0 | / __munge_args( $+{args} ) /sexmg; | |||||||||
| 23 | |||||||||||
| 24 | 0 | $file->content( $content ); | |||||||||
| 25 | |||||||||||
| 26 | 0 | return; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | sub __munge_args { | ||||||||||
| 30 | my $in = shift; | ||||||||||
| 31 | $in =~ s/\s+/ /g; | ||||||||||
| 32 | my @ins = split /\s*\|\s*/, $in; | ||||||||||
| 33 | |||||||||||
| 34 | my $theme = 'http://zoffix.com/CPAN/Dist-Zilla-Plugin-Pod-Spiffy/icons'; | ||||||||||
| 35 | # my $theme = 'http://zcms'; | ||||||||||
| 36 | my $method_icons = __method_icons($theme); | ||||||||||
| 37 | my $section_bits = __section_bits($theme); | ||||||||||
| 38 | my $out; | ||||||||||
| 39 | for ( @ins ) { | ||||||||||
| 40 | s/^\s+|\s+$//g; | ||||||||||
| 41 | if ( s/^authors?\s+// ){ | ||||||||||
| 42 | $out .= ' ' . __process_authors($theme, $_); | ||||||||||
| 43 | next; | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | tr/ /_/; | ||||||||||
| 47 | if ( s/^((?:start|end)_[^_]+)_section// ) { | ||||||||||
| 48 | $out .= $section_bits->{$1} ? ' ' . $section_bits->{$1} : ''; | ||||||||||
| 49 | next; | ||||||||||
| 50 | } | ||||||||||
| 51 | elsif ( /^hr$/ ) { | ||||||||||
| 52 | $out .= qq{<div style="background: url($theme/hr.png);} | ||||||||||
| 53 | . q{height: 18px;"></div>}; | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | next unless $method_icons->{$_}; | ||||||||||
| 57 | $out .= ' ' . $method_icons->{$_}; | ||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | return '' unless $out; | ||||||||||
| 61 | return '=for html ' . $out; | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | sub __process_authors { | ||||||||||
| 65 | my ( $theme, $authors ) = @_; | ||||||||||
| 66 | |||||||||||
| 67 | my @authors = $authors =~ /\S+/g; | ||||||||||
| 68 | my $out; | ||||||||||
| 69 | my $auth = Acme::CPANAuthors->new; | ||||||||||
| 70 | for ( map uc, @authors ) { | ||||||||||
| 71 | my $url = $auth->avatar_url($_) || ''; | ||||||||||
| 72 | $out .= qq{ | ||||||||||
| 73 | <span style="display: inline-block; text-align: center;"> | ||||||||||
| 74 | <a href="http://metacpan.org/author/$_"> | ||||||||||
| 75 | <img src="$url" alt="$_" | ||||||||||
| 76 | style="display: block; | ||||||||||
| 77 | margin: 0 3px 5px 0!important; | ||||||||||
| 78 | border: 1px solid #666; | ||||||||||
| 79 | border-radius: 3px; | ||||||||||
| 80 | "> | ||||||||||
| 81 | <span style="color: #333; font-weight: bold;">$_</span> | ||||||||||
| 82 | </a> | ||||||||||
| 83 | </span> | ||||||||||
| 84 | }; | ||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | $out =~ s/\s*\n\s*/ /g; | ||||||||||
| 88 | $out =~ s/\s+$//g; | ||||||||||
| 89 | return $out; | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | sub __section_bits { | ||||||||||
| 93 | my $theme = shift; | ||||||||||
| 94 | |||||||||||
| 95 | my @section_pics = qw/ | ||||||||||
| 96 | section-author.png | ||||||||||
| 97 | section-bugs.png | ||||||||||
| 98 | section-code.png | ||||||||||
| 99 | section-contributors.png | ||||||||||
| 100 | section-experimental.png | ||||||||||
| 101 | section-github.png | ||||||||||
| 102 | section-warning.png | ||||||||||
| 103 | /; | ||||||||||
| 104 | |||||||||||
| 105 | my %bits; | ||||||||||
| 106 | for my $pic ( @section_pics ) { | ||||||||||
| 107 | ( my $name = $pic ) =~ s/section-|\.png//g; | ||||||||||
| 108 | $name =~ tr/-/_/; | ||||||||||
| 109 | $bits{"start_$name"} = qq{<div style="display: table; height: 91px; | ||||||||||
| 110 | background: url($theme/$pic) no-repeat left; | ||||||||||
| 111 | padding-left: 120px;" | ||||||||||
| 112 | ><div style="display: table-cell; vertical-align: middle;">}; | ||||||||||
| 113 | $bits{"end_$name"} = '</div></div>'; | ||||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | s/\s*\n\s*/ /g for values %bits; | ||||||||||
| 117 | return \%bits; | ||||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | sub __method_icons { | ||||||||||
| 121 | my $theme = shift; | ||||||||||
| 122 | return { | ||||||||||
| 123 | in_arrayref => qq{<img alt="" src="$theme/in-arrayref.png">}, | ||||||||||
| 124 | in_hashref => qq{<img alt="" src="$theme/in-hashref.png">}, | ||||||||||
| 125 | in_key_value => qq{<img alt="" src="$theme/in-key-value.png">}, | ||||||||||
| 126 | in_list => qq{<img alt="" src="$theme/in-list.png">}, | ||||||||||
| 127 | in_no_args => qq{<img alt="" src="$theme/in-no-args.png">}, | ||||||||||
| 128 | in_object => qq{<img alt="" src="$theme/in-object.png">}, | ||||||||||
| 129 | in_scalar_optional | ||||||||||
| 130 | => qq{<img alt="" src="$theme/in-scalar-optional.png">}, | ||||||||||
| 131 | in_scalar_or_arrayref | ||||||||||
| 132 | => qq{<img alt="" src="$theme/in-scalar-or-arrayref.png">}, | ||||||||||
| 133 | in_scalar => qq{<img alt="" src="$theme/in-scalar.png">}, | ||||||||||
| 134 | in_scalar_scalar_optional | ||||||||||
| 135 | => qq{<img alt="" src="$theme/in-scalar-scalar-optional.png">}, | ||||||||||
| 136 | in_subref => qq{<img alt="" src="$theme/in-subref.png">}, | ||||||||||
| 137 | out_arrayref => qq{<img alt="" src="$theme/out-arrayref.png">}, | ||||||||||
| 138 | out_error_exception | ||||||||||
| 139 | => qq{<img alt="" src="$theme/out-error-exception.png">}, | ||||||||||
| 140 | out_error_undef_list | ||||||||||
| 141 | => qq{<img alt="" src="$theme/out-error-undef-list.png">}, | ||||||||||
| 142 | out_error_undef | ||||||||||
| 143 | => qq{<img alt="" src="$theme/out-error-undef.png">}, | ||||||||||
| 144 | out_hashref => qq{<img alt="" src="$theme/out-hashref.png">}, | ||||||||||
| 145 | out_key_value => qq{<img alt="" src="$theme/out-key-value.png">}, | ||||||||||
| 146 | out_list_or_arrayref | ||||||||||
| 147 | => qq{<img alt="" src="$theme/out-list-or-arrayref.png">}, | ||||||||||
| 148 | out_list => qq{<img alt="" src="$theme/out-list.png">}, | ||||||||||
| 149 | out_object => qq{<img alt="" src="$theme/out-object.png">}, | ||||||||||
| 150 | out_scalar => qq{<img alt="" src="$theme/out-scalar.png">}, | ||||||||||
| 151 | out_subref => qq{<img alt="" src="$theme/out-subref.png">}, | ||||||||||
| 152 | }; | ||||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 1 | q| | |||||||||
| 156 | Creativity is the feeling you get when you realize | ||||||||||
| 157 | your project is due tomorrow | ||||||||||
| 158 | |; | ||||||||||
| 159 | |||||||||||
| 160 | __END__ | ||||||||||