File Coverage

blib/lib/Acme/CPANModules/InterestingTies.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Acme::CPANModules::InterestingTies;
2              
3 1     1   248452 use strict;
  1         1  
  1         136  
4              
5             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6             our $DATE = '2023-10-31'; # DATE
7             our $DIST = 'Acme-CPANModules-InterestingTies'; # DIST
8             our $VERSION = '0.001'; # VERSION
9              
10             our $LIST = {
11             summary => "List of interesting uses of the tie() interface",
12             description => <<'MARKDOWN',
13              
14             The perl's tie interface allows you to create "magical" scalar, array, hash, or
15             filehandle. When you read or set the value of these variables, various things
16             can be triggered.
17              
18             This list catalogs some of the interesting uses of the
19             tie() interface.
20              
21             MARKDOWN
22             entries => [
23              
24             {
25             module => 'Acme::Tie::Formatted',
26             description => <<'MARKDOWN',
27              
28             This module allows you to do `sprintf()` by accessing a hash key, e.g.:
29              
30             print $format{17, "%03x"};
31              
32             will output:
33              
34             011
35              
36             The nice thing about this is that the `$format{...}` term can be put inside
37             double quote, although you have to use a different quote inside the quote, e.g.:
38              
39             print "The value is: $format{17, '%03x'}";
40             print qq(The value is: $format{17, "%03x"});
41              
42             The module advertises the functionality as "printf inside print", although the
43             author chose to accept a different argument order than printf. Instead of:
44              
45             FORMAT, LIST
46              
47             the FORMAT is put at the end:
48              
49             LIST, FORMAT
50              
51             MARKDOWN
52             },
53              
54             {
55             module => 'Regexp::Common',
56             description => <<'MARKDOWN',
57              
58             This module contains a collection of regular expression patterns. To access the
59             patterns, you can use the tied hash %RE, e.g.:
60              
61             $RE{quoted}
62             $RE{num}{real}
63              
64             You can also give arguments to customize the generated pattern:
65              
66             $RE{delimited}{-delim=>'/'}]
67              
68             The advantage, again, is being able to be used inside a regular expression
69             pattern.
70              
71             Note that the module also offers subroutine-based interface. I also created an
72             alternative module called which opts for the non-magical
73             subroutine-based interface and offers smaller startup overhead.
74              
75             MARKDOWN
76             },
77              
78             ],
79             };
80              
81             1;
82             # ABSTRACT: List of interesting uses of the tie() interface
83              
84             __END__