App::Greple Development Notes

Adding Options

1. Option Definition (script/greple:215-382)

2. Option Processing Flow (script/greple)

  1. Option parsing (~line 443)
  2. Encoding setup (~line 550)
  3. Pre-processing for new options (~line 556) — implicit settings go here
  4. Pattern construction (~line 565) — takes first ARGV as pattern if @opt_pattern is empty
  5. Count calculation (~line 610) — $count_must, $count_need, $count_allow
  6. Filter setup (~line 680)
  7. Color setup (~line 720)
  8. Grep execution loop (~line 1117)
  9. Exit — exit($opt_exit // ($stat{match_effective} == 0))

3. Controlling Pattern Requirement

Grep Engine (lib/App/Greple/Grep.pm)

Processing Flow: runpreparecompose

prepare

  1. Execute pattern matching → build @result and @blocks
  2. Region selection via --inside/--outside
  3. Region filtering via --include/--exclude
  4. BLOCKS construction: generate blocks from match ranges; [0, length] when nothing matched
  5. Build match table: POSI/NEGA/MUST counts per block

compose

Match Table Constants

POSI_POSI(0), POSI_NEGA(1), POSI_LIST(2)  # positive patterns
NEGA_POSI(3), NEGA_NEGA(4), NEGA_LIST(5)  # negative patterns
MUST_POSI(6), MUST_NEGA(7), MUST_LIST(8)  # required patterns

How --need=0 Works

Testing

Test Framework

Running Tests

prove -l t/              # all tests
prove -lv t/02_search.t  # single test, verbose

Module System

Debugging