| 1 | package Acme::PrettyCure::Girl::Role; | ||||||||||||||||||
| 2 | 16 | ▶ | use utf8; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | 16 | ▶ | use Moo::Role; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | 16 | ▶ | use Encode; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 16 | ▶ | use Furl; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 16 | ▶ | use Cache::LRU; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 16 | ▶ | use Net::DNS::Lite; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 16 | ▶ | use Imager; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 16 | $Net::DNS::Lite::CACHE = Cache::LRU->new(size => 256); | |||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 16 | requires qw(human_name precure_name challenge image_url); | |||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | has 'is_precure' => ( | ||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||
| 17 | 237 | ▶ | isa => sub { die "$_[0] is not a boolean" if $_[0] !~ /^[01]$/ }, | ||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||
| 18 | 183 | ▶ | default => sub {0} | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 19 | 16 | ); | |||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | sub say { | ||||||||||||||||||
| 22 | 102 | ▶ | my ($self, $text) = @_; | ||||||||||||||||
|
Subroutine
say: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||
| 23 | 102 | my $color = $self->color; | |||||||||||||||||
| 24 | 102 | ▶ | if ( defined $color ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 25 | 86 | print "\e[38;5;${color}m"; | |||||||||||||||||
| 26 | } | ||||||||||||||||||
| 27 | 102 | print encode_utf8("$text\n"); | |||||||||||||||||
| 28 | 102 | ▶ | if ( defined $color ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 29 | 86 | print "\e[0m"; | |||||||||||||||||
| 30 | } | ||||||||||||||||||
| 31 | } | ||||||||||||||||||
| 32 | |||||||||||||||||||
| 33 | 16 | ▶ | sub color { undef } | ||||||||||||||||
|
Subroutine
color: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | sub name { | ||||||||||||||||||
| 36 | 70 | ▶ | my $self = shift; | ||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 70 | ▶ | return $self->is_precure ? $self->precure_name : $self->human_name; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | sub transform { | ||||||||||||||||||
| 42 | 48 | ▶ | my ($self, $buddy) = @_; | ||||||||||||||||
|
Subroutine
transform: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | 48 | ▶ | die "already transformed" if $self->is_precure; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | 48 | $self->is_precure(1); | |||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 48 | $self->say($_) for $self->challenge; | |||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | 48 | return $self; | |||||||||||||||||
| 51 | } | ||||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | sub image { | ||||||||||||||||||
| 54 | 0 | ▶ | my $self = shift; | ||||||||||||||||
|
Subroutine
image: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | 0 | my $furl = Furl::HTTP->new( | |||||||||||||||||
| 57 | agent => 'Acme-PrettyCure', | ||||||||||||||||||
| 58 | inet_aton => \&Net::DNS::Lite::inet_aton, | ||||||||||||||||||
| 59 | timeout => 60, | ||||||||||||||||||
| 60 | ); | ||||||||||||||||||
| 61 | 0 | my ( $minor_version, $status, $message, $headers, $content ) = | |||||||||||||||||
| 62 | $furl->request( method => 'GET', url => $self->image_url, ); | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | 0 | my $img = Imager->new(); | |||||||||||||||||
| 65 | 0 | my $type; | |||||||||||||||||
| 66 | 0 | ▶ | if ($self->image_url =~ /\.gif$/) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 67 | 0 | $type = 'gif'; | |||||||||||||||||
| 68 | } | ||||||||||||||||||
| 69 | elsif ($self->image_url =~ /\.png$/) { | ||||||||||||||||||
| 70 | 0 | $type = 'png'; | |||||||||||||||||
| 71 | } | ||||||||||||||||||
| 72 | elsif ($self->image_url =~ /\.jpe?g$/) { | ||||||||||||||||||
| 73 | 0 | $type = 'jpeg'; | |||||||||||||||||
| 74 | } | ||||||||||||||||||
| 75 | 0 | ▶ | $img->read(data => $content, type => $type) or die $img->errstr; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | 0 | ▶ | open my $ah, '|-', qw/aview -reverse -driver curses/ or die "aview:$!"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 78 | 0 | ▶ | $img->write( fh => $ah, type => 'pnm' ) or die $img->errstr; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 79 | 0 | close($ah); | |||||||||||||||||
| 80 | } | ||||||||||||||||||
| 81 | |||||||||||||||||||
| 82 | 16 | 1; | |||||||||||||||||
| 83 | __END__ | ||||||||||||||||||