| 1 | package Venus::Text::Pod; | ||
| 2 | |||
| 3 | 119 | ▶ | use 5.018; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 119 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 119 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | # VENUS | ||
| 9 | |||
| 10 | 119 | ▶ | use Venus::Class 'base'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | # IMPORTS | ||
| 13 | |||
| 14 | 119 | ▶ | use Venus::Path; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | # INHERITS | ||
| 17 | |||
| 18 | 119 | base 'Venus::Text'; | |
| 19 | |||
| 20 | # METHODS | ||
| 21 | |||
| 22 | 12179 | ▶ | sub data { |
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||
| 23 | 12179 | my ($self) = @_; | |
| 24 | |||
| 25 | 12179 | my $file = $self->file; | |
| 26 | |||
| 27 | 12179 | my $data = Venus::Path->new($file)->read; | |
| 28 | |||
| 29 | 12178 | return $data; | |
| 30 | } | ||
| 31 | |||
| 32 | 12177 | ▶ | sub stag { |
|
Subroutine
stag: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 33 | |||
| 34 | 12177 | return '='; | |
| 35 | } | ||
| 36 | |||
| 37 | 12177 | ▶ | sub etag { |
|
Subroutine
etag: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 38 | |||
| 39 | 12177 | return '=cut'; | |
| 40 | } | ||
| 41 | |||
| 42 | 119 | 1; | |
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | =head1 NAME | ||
| 47 | |||
| 48 | Venus::Text::Pod - Text (Pod) Class | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | =head1 ABSTRACT | ||
| 53 | |||
| 54 | Text (Pod) Class for Perl 5 | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | =head1 SYNOPSIS | ||
| 59 | |||
| 60 | package main; | ||
| 61 | |||
| 62 | use Venus::Text::Pod; | ||
| 63 | |||
| 64 | my $text = Venus::Text::Pod->new('t/data/sections'); | ||
| 65 | |||
| 66 | # $text->find(undef, 'name'); | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | =head1 DESCRIPTION | ||
| 71 | |||
| 72 | This package provides methods for extracting POD blocks from any file or | ||
| 73 | package. | ||
| 74 | |||
| 75 | =head2 POD syntax | ||
| 76 | |||
| 77 | # pod syntax | ||
| 78 | |||
| 79 | =head1 NAME | ||
| 80 | |||
| 81 | Example #1 | ||
| 82 | |||
| 83 | =cut | ||
| 84 | |||
| 85 | =head1 NAME | ||
| 86 | |||
| 87 | Example #2 | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | # pod-ish syntax | ||
| 92 | |||
| 93 | =name | ||
| 94 | |||
| 95 | Example #1 | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | =name | ||
| 100 | |||
| 101 | Example #2 | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | =head2 POD syntax (nested) | ||
| 106 | |||
| 107 | # pod syntax (nested) | ||
| 108 | |||
| 109 | =nested | ||
| 110 | |||
| 111 | Example #1 | ||
| 112 | |||
| 113 | +=head1 WHY? | ||
| 114 | |||
| 115 | blah blah blah | ||
| 116 | |||
| 117 | +=cut | ||
| 118 | |||
| 119 | More information on the same topic as was previously mentioned in the | ||
| 120 | previous section demonstrating the topic, obviously from said section. | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | =head1 METHODS | ||
| 127 | |||
| 128 | This package provides the following methods: | ||
| 129 | |||
| 130 | =cut | ||
| 131 | |||
| 132 | =head2 count | ||
| 133 | |||
| 134 | count(hashref $criteria) (number) | ||
| 135 | |||
| 136 | The count method uses the criteria provided to L</search> for and return the | ||
| 137 | number of blocks found. | ||
| 138 | |||
| 139 | I<Since C<4.15>> | ||
| 140 | |||
| 141 | =over 4 | ||
| 142 | |||
| 143 | =item count example 1 | ||
| 144 | |||
| 145 | # given: synopsis; | ||
| 146 | |||
| 147 | my $count = $text->count; | ||
| 148 | |||
| 149 | # 7 | ||
| 150 | |||
| 151 | =back | ||
| 152 | |||
| 153 | =cut | ||
| 154 | |||
| 155 | =head2 data | ||
| 156 | |||
| 157 | data() (string) | ||
| 158 | |||
| 159 | The data method returns the contents of the L</file> to be parsed. | ||
| 160 | |||
| 161 | I<Since C<4.15>> | ||
| 162 | |||
| 163 | =over 4 | ||
| 164 | |||
| 165 | =item data example 1 | ||
| 166 | |||
| 167 | # given: synopsis; | ||
| 168 | |||
| 169 | $text = $text->data; | ||
| 170 | |||
| 171 | # ... | ||
| 172 | |||
| 173 | =back | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | =head2 find | ||
| 178 | |||
| 179 | find(maybe[string] $list, maybe[string] $name) (arrayref) | ||
| 180 | |||
| 181 | The find method is a wrapper around L</search> as shorthand for searching by | ||
| 182 | C<list> and C<name>. | ||
| 183 | |||
| 184 | I<Since C<4.15>> | ||
| 185 | |||
| 186 | =over 4 | ||
| 187 | |||
| 188 | =item find example 1 | ||
| 189 | |||
| 190 | # given: synopsis; | ||
| 191 | |||
| 192 | my $find = $text->find(undef, 'name'); | ||
| 193 | |||
| 194 | # [ | ||
| 195 | # { data => ["Example #1"], index => 4, list => undef, name => "name" }, | ||
| 196 | # { data => ["Example #2"], index => 5, list => undef, name => "name" }, | ||
| 197 | # ] | ||
| 198 | |||
| 199 | =back | ||
| 200 | |||
| 201 | =over 4 | ||
| 202 | |||
| 203 | =item find example 2 | ||
| 204 | |||
| 205 | # given: synopsis; | ||
| 206 | |||
| 207 | my $find = $text->find('head1', 'NAME'); | ||
| 208 | |||
| 209 | # [ | ||
| 210 | # { data => ["Example #1"], index => 1, list => "head1", name => "NAME" }, | ||
| 211 | # { data => ["Example #2"], index => 2, list => "head1", name => "NAME" }, | ||
| 212 | # ] | ||
| 213 | |||
| 214 | =back | ||
| 215 | |||
| 216 | =cut | ||
| 217 | |||
| 218 | =head2 new | ||
| 219 | |||
| 220 | new(any @args) (Venus::Text::Pod) | ||
| 221 | |||
| 222 | The new method constructs an instance of the package. | ||
| 223 | |||
| 224 | I<Since C<4.15>> | ||
| 225 | |||
| 226 | =over 4 | ||
| 227 | |||
| 228 | =item new example 1 | ||
| 229 | |||
| 230 | package main; | ||
| 231 | |||
| 232 | use Venus::Text::Pod; | ||
| 233 | |||
| 234 | my $new = Venus::Text::Pod->new; | ||
| 235 | |||
| 236 | # bless(..., "Venus::Text::Pod") | ||
| 237 | |||
| 238 | =back | ||
| 239 | |||
| 240 | =over 4 | ||
| 241 | |||
| 242 | =item new example 2 | ||
| 243 | |||
| 244 | package main; | ||
| 245 | |||
| 246 | use Venus::Text::Pod; | ||
| 247 | |||
| 248 | my $new = Venus::Text::Pod->new('t/data/sections'); | ||
| 249 | |||
| 250 | # bless(..., "Venus::Text::Pod") | ||
| 251 | |||
| 252 | =back | ||
| 253 | |||
| 254 | =over 4 | ||
| 255 | |||
| 256 | =item new example 3 | ||
| 257 | |||
| 258 | package main; | ||
| 259 | |||
| 260 | use Venus::Text::Pod; | ||
| 261 | |||
| 262 | my $new = Venus::Text::Pod->new(file => 't/data/sections'); | ||
| 263 | |||
| 264 | # bless(..., "Venus::Text::Pod") | ||
| 265 | |||
| 266 | =back | ||
| 267 | |||
| 268 | =cut | ||
| 269 | |||
| 270 | =head2 search | ||
| 271 | |||
| 272 | find(hashref $criteria) (arrayref) | ||
| 273 | |||
| 274 | The search method returns the set of blocks matching the criteria provided. | ||
| 275 | This method can return a list of values in list-context. | ||
| 276 | |||
| 277 | I<Since C<4.15>> | ||
| 278 | |||
| 279 | =over 4 | ||
| 280 | |||
| 281 | =item search example 1 | ||
| 282 | |||
| 283 | # given: synopsis; | ||
| 284 | |||
| 285 | my $search = $text->search({list => undef, name => 'name'}); | ||
| 286 | |||
| 287 | # [ | ||
| 288 | # { data => ["Example #1"], index => 4, list => undef, name => "name" }, | ||
| 289 | # { data => ["Example #2"], index => 5, list => undef, name => "name" }, | ||
| 290 | # ] | ||
| 291 | |||
| 292 | =back | ||
| 293 | |||
| 294 | =over 4 | ||
| 295 | |||
| 296 | =item search example 2 | ||
| 297 | |||
| 298 | # given: synopsis; | ||
| 299 | |||
| 300 | my $search = $text->search({list => 'head1', name => 'NAME'}); | ||
| 301 | |||
| 302 | # [ | ||
| 303 | # { data => ["Example #1"], index => 1, list => "head1", name => "NAME" }, | ||
| 304 | # { data => ["Example #2"], index => 2, list => "head1", name => "NAME" }, | ||
| 305 | # ] | ||
| 306 | |||
| 307 | =back | ||
| 308 | |||
| 309 | =cut | ||
| 310 | |||
| 311 | =head2 string | ||
| 312 | |||
| 313 | string(maybe[string] $list, maybe[string] $name) (string) | ||
| 314 | |||
| 315 | The string method is a wrapper around L</find> as shorthand for searching by | ||
| 316 | C<list> and C<name>, returning only the strings found. | ||
| 317 | |||
| 318 | I<Since C<4.15>> | ||
| 319 | |||
| 320 | =over 4 | ||
| 321 | |||
| 322 | =item string example 1 | ||
| 323 | |||
| 324 | # given: synopsis; | ||
| 325 | |||
| 326 | my $string = $text->string(undef, 'name'); | ||
| 327 | |||
| 328 | # "Example #1\nExample #2" | ||
| 329 | |||
| 330 | =back | ||
| 331 | |||
| 332 | =over 4 | ||
| 333 | |||
| 334 | =item string example 2 | ||
| 335 | |||
| 336 | # given: synopsis; | ||
| 337 | |||
| 338 | my $string = $text->string('head1', 'NAME'); | ||
| 339 | |||
| 340 | # "Example #1\nExample #2" | ||
| 341 | |||
| 342 | =back | ||
| 343 | |||
| 344 | =over 4 | ||
| 345 | |||
| 346 | =item string example 3 | ||
| 347 | |||
| 348 | # given: synopsis; | ||
| 349 | |||
| 350 | my @string = $text->string('head1', 'NAME'); | ||
| 351 | |||
| 352 | # ("Example #1", "Example #2") | ||
| 353 | |||
| 354 | =back | ||
| 355 | |||
| 356 | =cut | ||
| 357 | |||
| 358 | =head1 AUTHORS | ||
| 359 | |||
| 360 | Awncorp, C<awncorp@cpan.org> | ||
| 361 | |||
| 362 | =cut | ||
| 363 | |||
| 364 | =head1 LICENSE | ||
| 365 | |||
| 366 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||
| 367 | |||
| 368 | This program is free software, you can redistribute it and/or modify it under | ||
| 369 | the terms of the Apache license version 2.0. | ||
| 370 | |||
| 371 | =cut | ||