| 1 | package BorderStyleRole::Source::ASCIIArt; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Role::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Role::Tiny::With; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | with 'BorderStyleRole::Source::Hash'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 10 | 1 | our $DATE = '2023-07-14'; # DATE | |||||||||
| 11 | 1 | our $DIST = 'BorderStyle'; # DIST | |||||||||
| 12 | 1 | our $VERSION = '3.0.3'; # VERSION | |||||||||
| 13 | |||||||||||
| 14 | # offsets after newlines are removed | ||||||||||
| 15 | # 012345678901234567 | ||||||||||
| 16 | # ┌───────┬───┬───┐' | ||||||||||
| 17 | #+ 18│ ..... │ . │ . │' | ||||||||||
| 18 | #+ 36│ ..... ├───┼───┤' | ||||||||||
| 19 | #+ 54│ ..... │ . │ . │' | ||||||||||
| 20 | #+ 72│ ..... ├───┴───┤' | ||||||||||
| 21 | #+ 90│ ..... │ ..... │' | ||||||||||
| 22 | #+108├───┬───┤ ..... │' | ||||||||||
| 23 | #+126│ . │ . │ ..... │' | ||||||||||
| 24 | #+144└───┴───┴───────┘' | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | around get_border_char => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=35.3
| |||||||||||
| 27 | 0 | my $orig = shift; | |||||||||
| 28 | |||||||||||
| 29 | #my ($self, %ags) = @_; | ||||||||||
| 30 | 0 | my $self = $_[0]; | |||||||||
| 31 | |||||||||||
| 32 | #use DD; dd {@_[1.. $#_]}; | ||||||||||
| 33 | |||||||||||
| 34 | # initialize %CHARS from $PICTURE | ||||||||||
| 35 | { | ||||||||||
| 36 | 1 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | my $picture = ${"$self->{orig_class}::PICTURE"}; | |||||||||
| 39 | 0 | ▶ | last unless defined $picture; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | my $chars = \%{"$self->{orig_class}::CHARS"}; | |||||||||
| 42 | 0 | ▶ | last if keys %$chars; # already initialized | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | #say "D1"; | ||||||||||
| 45 | 0 | $picture =~ s/\R//g; | |||||||||
| 46 | 0 | $chars->{h_b} = substr($picture, 144+ 1, 1); # 1 | |||||||||
| 47 | 0 | $chars->{h_i} = substr($picture, 108+ 1, 1); # 2 | |||||||||
| 48 | 0 | $chars->{h_t} = substr($picture, 1, 1); # 3 | |||||||||
| 49 | 0 | $chars->{hd_i} = substr($picture, 108+ 4, 1); # 4 | |||||||||
| 50 | 0 | $chars->{hd_t} = substr($picture, 8, 1); # 5 | |||||||||
| 51 | 0 | $chars->{hu_b} = substr($picture, 144+ 4, 1); # 6 | |||||||||
| 52 | 0 | $chars->{hu_i} = substr($picture, 72+12, 1); # 7 | |||||||||
| 53 | 0 | $chars->{hv_i} = substr($picture, 36+12, 1); # 8 | |||||||||
| 54 | 0 | $chars->{ld_t} = substr($picture, 16, 1); # 9 | |||||||||
| 55 | 0 | $chars->{lu_b} = substr($picture, 144+16, 1); # 10 | |||||||||
| 56 | 0 | $chars->{lv_i} = substr($picture, 108+ 8, 1); # 11 | |||||||||
| 57 | 0 | $chars->{lv_r} = substr($picture, 36+16, 1); # 12 | |||||||||
| 58 | 0 | $chars->{rd_t} = substr($picture, 0, 1); # 13 | |||||||||
| 59 | 0 | $chars->{ru_b} = substr($picture, 144+ 0, 1); # 14 | |||||||||
| 60 | 0 | $chars->{rv_i} = substr($picture, 36+ 8, 1); # 15 | |||||||||
| 61 | 0 | $chars->{rv_l} = substr($picture, 108+ 0, 1); # 16 | |||||||||
| 62 | 0 | $chars->{v_i} = substr($picture, 18+ 8, 1); # 17 | |||||||||
| 63 | 0 | $chars->{v_l} = substr($picture, 18+ 0, 1); # 18 | |||||||||
| 64 | 0 | $chars->{v_r} = substr($picture, 18+16, 1); # 19 | |||||||||
| 65 | #no strict 'refs'; use DDC; dd \%{"$self->{orig_class}::CHARS"}; | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | # initialize @MULTI_CHARS from @PICTURES | ||||||||||
| 69 | { | ||||||||||
| 70 | 0 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||
| 71 | |||||||||||
| 72 | 0 | my $pictures = \@{"$self->{orig_class}::PICTURES"}; | |||||||||
| 73 | 0 | ▶ | last unless @$pictures; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | |||||||||||
| 75 | 0 | my $multi_chars = \@{"$self->{orig_class}::MULTI_CHARS"}; | |||||||||
| 76 | 0 | ▶ | last if @$multi_chars; # already initialized | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | |||||||||||
| 78 | #say "D2"; | ||||||||||
| 79 | 0 | for my $entry (@$pictures) { | |||||||||
| 80 | 0 | my $chars = {}; | |||||||||
| 81 | 0 | my $picture = $entry->{picture}; | |||||||||
| 82 | 0 | $picture =~ s/\R//g; | |||||||||
| 83 | 0 | $chars->{h_b} = substr($picture, 144+ 1, 1); # 1 | |||||||||
| 84 | 0 | $chars->{h_i} = substr($picture, 108+ 1, 1); # 2 | |||||||||
| 85 | 0 | $chars->{h_t} = substr($picture, 1, 1); # 3 | |||||||||
| 86 | 0 | $chars->{hd_i} = substr($picture, 108+ 4, 1); # 4 | |||||||||
| 87 | 0 | $chars->{hd_t} = substr($picture, 8, 1); # 5 | |||||||||
| 88 | 0 | $chars->{hu_b} = substr($picture, 144+ 4, 1); # 6 | |||||||||
| 89 | 0 | $chars->{hu_i} = substr($picture, 72+12, 1); # 7 | |||||||||
| 90 | 0 | $chars->{hv_i} = substr($picture, 36+12, 1); # 8 | |||||||||
| 91 | 0 | $chars->{ld_t} = substr($picture, 16, 1); # 9 | |||||||||
| 92 | 0 | $chars->{lu_b} = substr($picture, 144+16, 1); # 10 | |||||||||
| 93 | 0 | $chars->{lv_i} = substr($picture, 108+ 8, 1); # 11 | |||||||||
| 94 | 0 | $chars->{lv_r} = substr($picture, 36+16, 1); # 12 | |||||||||
| 95 | 0 | $chars->{rd_t} = substr($picture, 0, 1); # 13 | |||||||||
| 96 | 0 | $chars->{ru_b} = substr($picture, 144+ 0, 1); # 14 | |||||||||
| 97 | 0 | $chars->{rv_i} = substr($picture, 36+ 8, 1); # 15 | |||||||||
| 98 | 0 | $chars->{rv_l} = substr($picture, 108+ 0, 1); # 16 | |||||||||
| 99 | 0 | $chars->{v_i} = substr($picture, 18+ 8, 1); # 17 | |||||||||
| 100 | 0 | $chars->{v_l} = substr($picture, 18+ 0, 1); # 18 | |||||||||
| 101 | 0 | $chars->{v_r} = substr($picture, 18+16, 1); # 19 | |||||||||
| 102 | |||||||||||
| 103 | 0 | push @$multi_chars, { | |||||||||
| 104 | %$entry, | ||||||||||
| 105 | chars => $chars, | ||||||||||
| 106 | }; | ||||||||||
| 107 | } | ||||||||||
| 108 | #no strict 'refs'; use DDC; dd \@{"$self->{orig_class}::MULTI_CHARS"}; | ||||||||||
| 109 | } # init @MULTI_CHARS | ||||||||||
| 110 | |||||||||||
| 111 | # pass | ||||||||||
| 112 | 0 | $orig->(@_); | |||||||||
| 113 | 1 | }; | |||||||||
| 114 | |||||||||||
| 115 | 1 | 1; | |||||||||
| 116 | # ABSTRACT: Get border characters from ASCII art | ||||||||||
| 117 | |||||||||||
| 118 | __END__ | ||||||||||