blib/lib/Venus/Text/Tag.pm

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