Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day bliako,

As requested, here's some comments and suggestions.

Naming

Subroutine names with a leading underscore tend to suggest private methods or implementation details; these are generally for internal use and not for users of module, i.e. not part of the interface — _qquote_redefinition_by_Corion() is a part of the implementation and the leading underscore is appropriate. The other four subroutines (_read_from_* and _write_to_*) are, in my opinion, part of the interface — consider removing the leading underscore from these.

Exporting

I wouldn't export those ten subroutines by default (i.e. via @EXPORT); in fact, I wouldn't export anything by default, instead using @EXPORT_OK as recommended in "Exporter: Selecting What to Export".

In addition to using @EXPORT_OK, I would add %EXPORT_TAGS so that users of the module do not have to write long import lists. The following is an example of what can be done; it is not a recommendation of what you should do, although I do think something along these lines is a good idea.

use Exporter 'import'; our (@EXPORT_OK, %EXPORT_TAGS); BEGIN { my @file = qw{read_from_file write_to_file}; my @fh = qw{read_from_filehandle write_to_filehandle}; my @io = (@file, @fh); my @json = qw{perl2json json2perl}; my @yaml = qw{perl2yaml yaml2perl}; my @dump = qw{perl2dump dump2perl}; my @all = (@io, @json, @yaml, @dump); @EXPORT_OK = @all; %EXPORT_TAGS = ( file => [@file], fh => [@fh], io => [@io], json => [@json], yaml => [@yaml], dump => [@dump], all => [@all], ); }

Layout

Some of your code layout could be improved. Lines like this one are not easy to read:

if( ! _write_to_filehandle($FH, $contents) ){ warn "error, call to ".' +_write_to_filehandle()'." has failed"; close $FH; return undef }

That's 134 characters long; plus there's leading whitespace for indentation. This would be much more readable, at least in my opinion, as:

if( ! _write_to_filehandle($FH, $contents) ) { warn "error, call to ".'_write_to_filehandle()'." has failed"; close $FH; return undef; }

— Ken


In reply to Re: RFC: Perl<->JSON<->YAML<->Dumper : roundtripping and possibly with unicode by kcott
in thread RFC: Perl<->JSON<->YAML<->Dumper : roundtripping and possibly with unicode by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found