| 1 | package Term::Fabulous::Role::SearchContainer; | ||
| 2 | |||
| 3 | 1 | ▶ | use v5.32; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use feature 'signatures'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | no warnings 'experimental::signatures'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | our $VERSION = '0.05'; | ||
| 9 | |||
| 10 | 1 | ▶ | use Object::Pad 0.825; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 0 | ▶ | use Term::Fabulous::Role::Searchable; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 13 | |||
| 14 | role Term::Fabulous::Role::SearchContainer | ||
| 15 | :does(Term::Fabulous::Role::Searchable) | ||
| 16 | { | ||
| 17 | use Term::Fabulous::Role::Searchable qw(nested_part nested_search_texts nested_search_revision nested_highlight_text nested_clear_text_highlights nested_reveal_text); | ||
| 18 | |||
| 19 | # The searchable widgets the container answers for, in order. | ||
| 20 | method searchable_parts; | ||
| 21 | |||
| 22 | method search_texts () { | ||
| 23 | return nested_search_texts( [ $self->searchable_parts ] ); | ||
| 24 | } | ||
| 25 | |||
| 26 | method search_revision ($key) { | ||
| 27 | return nested_search_revision( [ $self->searchable_parts ], $key ); | ||
| 28 | } | ||
| 29 | |||
| 30 | method highlight_text ( $key, $ranges ) { | ||
| 31 | nested_highlight_text( [ $self->searchable_parts ], $key, $ranges ); | ||
| 32 | return; | ||
| 33 | } | ||
| 34 | |||
| 35 | method clear_text_highlights () { | ||
| 36 | nested_clear_text_highlights( [ $self->searchable_parts ] ); | ||
| 37 | return; | ||
| 38 | } | ||
| 39 | |||
| 40 | # The container first shows the part (reveal_part, when it has one), | ||
| 41 | # then the part shows its text. | ||
| 42 | method reveal_text ( $key, $offset ) { | ||
| 43 | my @parts = $self->searchable_parts; | ||
| 44 | my $part = nested_part( \@parts, $key ); | ||
| 45 | $self->reveal_part($part) if defined $part && $self->can('reveal_part'); | ||
| 46 | return nested_reveal_text( \@parts, $key, $offset ); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; | ||
| 51 | |||
| 52 | __END__ | ||