.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Smart::Comments 3pm" .TH Smart::Comments 3pm "2015-10-24" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Smart::Comments \- Comments that do more than just sit there .SH "VERSION" .IX Header "VERSION" This document describes Smart::Comments version 1.000005 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Smart::Comments; \& \& my $var = suspect_value(); \& \& ### $var \& \& ### got: $var \& \& ### Now computing value... \& \& # and when looping: \& \& for my $big_num (@big_nums) { ### Factoring... done \& factor($big_num); \& } \& \& while ($error > $tolerance) { ### Refining\-\-\-> done \& refine_approximation() \& } \& \& for (my $i=0; $i<$MAX_INT; $i++) { ### Working===[%] done \& do_something_expensive_with($i); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Smart comments provide an easy way to insert debugging and tracking code into a program. They can report the value of a variable, track the progress of a loop, and verify that particular assertions are true. .PP Best of all, when you're finished debugging, you don't have to remove them. Simply commenting out the \f(CW\*(C`use Smart::Comments\*(C'\fR line turns them back into regular comments. Leaving smart comments in your code is smart because if you needed them once, you'll almost certainly need them again later. .SH "INTERFACE" .IX Header "INTERFACE" All smart comments start with three (or more) \f(CW\*(C`#\*(C'\fR characters. That is, they are regular \f(CW\*(C`#\*(C'\fR\-introduced comments whose first two (or more) characters are also \f(CW\*(C`#\*(C'\fR's. .SS "Using the Module" .IX Subsection "Using the Module" The module is loaded like any other: .PP .Vb 1 \& use Smart::Comments; .Ve .PP When loaded it filters the remaining code up to the next: .PP .Vb 1 \& no Smart::Comments; .Ve .PP directive, replacing any smart comments with smart code that implements the comments behaviour. .PP If you're debugging an application you can also invoke it with the module from the command-line: .PP .Vb 1 \& perl \-MSmart::Comments $application.pl .Ve .PP Of course, this only enables smart comments in the application file itself, not in any modules that the application loads. .PP You can also specify particular levels of smartness, by including one or more markers as arguments to the \f(CW\*(C`use\*(C'\fR: .PP .Vb 1 \& use Smart::Comments \*(Aq###\*(Aq, \*(Aq####\*(Aq; .Ve .PP These arguments tell the module to filter only those comments that start with the same number of \f(CW\*(C`#\*(C'\fR's. So the above \f(CW\*(C`use\*(C'\fR statement would \*(L"activate\*(R" any smart comments of the form: .PP .Vb 1 \& ### Smart... \& \& #### Smarter... .Ve .PP but not those of the form: .PP .Vb 1 \& ##### Smartest... .Ve .PP This facility is useful for differentiating progress bars (see \&\*(L"Progress Bars\*(R"), which should always be active, from debugging comments (see \*(L"Debugging via Comments\*(R"), which should not: .PP .Vb 1 \& #### Debugging here... \& \& for (@values) { ### Progress: 0... 100 \& do_stuff(); \& } .Ve .PP Note that, for simplicity, all smart comments described below will be written with three \f(CW\*(C`#\*(C'\fR's; in all such cases, any number of \f(CW\*(C`#\*(C'\fR's greater than three could be used instead. .SS "Debugging via Comments" .IX Subsection "Debugging via Comments" The simplest way to use smart comments is for debugging. The module supports the following forms, all of which print to \f(CW\*(C`STDERR\*(C'\fR: .ie n .IP """### LABEL : EXPRESSION""" 4 .el .IP "\f(CW### LABEL : EXPRESSION\fR" 4 .IX Item "### LABEL : EXPRESSION" The \s-1LABEL\s0 is any sequence of characters up to the first colon. The \s-1EXPRESSION\s0 is any valid Perl expression, including a simple variable. When active, the comment prints the label, followed by the value of the expression. For example: .Sp .Vb 2 \& ### Expected: 2 * $prediction \& ### Got: $result .Ve .Sp prints: .Sp .Vb 2 \& ### Expected: 42 \& ### Got: 13 .Ve .ie n .IP """### EXPRESSION""" 4 .el .IP "\f(CW### EXPRESSION\fR" 4 .IX Item "### EXPRESSION" The \s-1EXPRESSION\s0 is any valid Perl expression, including a simple variable. When active, the comment prints the expression, followed by the value of the expression. For example: .Sp .Vb 2 \& ### 2 * $prediction \& ### $result .Ve .Sp prints: .Sp .Vb 2 \& ### 2 * $prediction: 42 \& ### $result: 13 .Ve .ie n .IP """### TEXT...""" 4 .el .IP "\f(CW### TEXT...\fR" 4 .IX Item "### TEXT..." The \s-1TEXT\s0 is any sequence of characters that end in three dots. When active, the comment just prints the text, including the dots. For example: .Sp .Vb 1 \& ### Acquiring data... \& \& $data = get_data(); \& \& ### Verifying data... \& \& verify_data($data); \& \& ### Assimilating data... \& \& assimilate_data($data); \& \& ### Tired now, having a little lie down... \& \& sleep 900; .Ve .Sp would print: .Sp .Vb 1 \& ### Acquiring data... \& \& ### Verifying data... \& \& ### Assimilating data... \& \& ### Tired now, having a little lie down... .Ve .Sp as each phase commenced. This is particularly useful for tracking down precisely where a bug is occurring. It is also useful in non-debugging situations, especially when batch processing, as a simple progress feedback mechanism. .Sp Within a textual smart comment you can use the special sequence \f(CW\*(C`\*(C'\fR (or \f(CW\*(C`