Data-Roundtrip

 view release on metacpan or  search on metacpan

a.html  view on Meta::CPAN

<h2 id="write_to_filehandle"><code>write_to_filehandle</code></h2>

<pre><code>write_to_filehandle($filehandle, $contents) or die</code></pre>

<p>Arguments:</p>

<ul>

<li><p><code>$filehandle</code> : the handle to an already opened file (for writing).</p>

</li>
</ul>

<p>Return value:</p>

<ul>

<li><p>1 on success or 0 on failure.</p>

</li>
</ul>

<p>It writes content to the specified file handle. Upon return the file handle is still open.</p>

<p>It returns 1 on success or 0 on failure.</p>

<h1 id="SCRIPTS">SCRIPTS</h1>

<p>A few scripts have been put together and offer the functionality of this module to the command line. They are part of this distribution and can be found in the <code>script</code> directory.</p>

<p>These are: <code>json2json.pl</code>, <code>json2yaml.pl</code>, <code>yaml2json.pl</code>, <code>json2perl.pl</code>, <code>perl2json.pl</code>, <code>yaml2perl.pl</code></p>

<h1 id="CAVEATS">CAVEATS</h1>

<p>I have to apologise here to the authors of <a>YAML::PP</a> for defaming them because I clumsily wrote <a>YAML::PP</a> when I wanted to write <a>YAML</a>.</p>

<p>So, the reality is that <a>YAML::PP</a> does not have any problem in handling the edge-case below.</p>

<p>A valid Perl variable may kill <a>YAML</a>&#39;s <code>Load()</code> because of escapes and quotes. For example this:</p>

<pre><code>my $yamlstr = &lt;&lt;&#39;EOS&#39;;
---
- 682224
- &quot;\&quot;w&quot;: 1
EOS
my $pv = eval { YAML::Load($yamlstr) };
if( $@ ){ die &quot;failed(1): &quot;. $@ }
# it&#39;s dead</code></pre>

<p>Strangely, there is no problem for this:</p>

<pre><code>my $yamlstr = &lt;&lt;&#39;EOS&#39;;
---
- 682224
- &quot;\&quot;w&quot;
EOS
# this is OK also:
# - \&quot;w: 1
my $pv = eval { YAML::Load($yamlstr) };
if( $@ ){ die &quot;failed(1): &quot;. $@ }
# it&#39;s OK! still alive.</code></pre>

<p>I have provided an author-only test (<code>make deficiencies</code>) which tests all three of them on the edge cases. Both <a>YAML::PP</a> and <a>YAML::XS</a> pass the tests.</p>

<p>This <a href="https://github.com/ingydotnet/yaml-pm/issues/224">YAML issue</a> is relevant. Many thanks to CPAN authors <a href="https://metacpan.org/author/TINITA">TINITA</a> and <a href="https://metacpan.org/author/INGY">INGY</a> for their work ...

<p>For now, the plan is to still use <a>YAML::PP</a> and avoid explicitly requiring <a>YAML::XS</a> until <a>YAML::Any</a> is ready.</p>

<p>Be warned that sub <code>dump2perl()</code> <code>eval()</code>&#39;s its input. If this comes from the user and it is not checked then it is considered a security problem. Subs <code>dump2json()</code>, <code>dump2yaml()</code>, <code>dump2dump()...

<pre><code>use Data::Roundtrip qw/... dump2perl .../</code></pre>

<p>They are no longer part of export tag <code>:dump</code> nor <code>:all</code>. If their input comes from the user please check the input not to contain malicious code which when <code>eval()</code>&#39;ed can create security concerns.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>Andreas Hadjiprocopis, <code>&lt;bliako at cpan.org&gt; / &lt;andreashad2 at gmail.com&gt;</code></p>

<h1 id="BUGS">BUGS</h1>

<p>Please report any bugs or feature requests to <code>bug-data-roundtrip at rt.cpan.org</code>, or through the web interface at <a href="https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Roundtrip">https://rt.cpan.org/NoAuth/ReportBug.html?Queue=...

<h1 id="SEE-ALSO">SEE ALSO</h1>

<dl>

<dt id="Convert-JSON-to-Perl-and-back-with-unicode"><a href="https://perlmonks.org/?node_id=11115241">Convert JSON to Perl and back with unicode</a></dt>
<dd>

</dd>
<dt id="RFC:-Perl-JSON-YAML-Dumper-:-roundtripping-and-possibly-with-unicode"><a href="https://perlmonks.org/?node_id=11115280">RFC: Perl&lt;-&gt;JSON&lt;-&gt;YAML&lt;-&gt;Dumper : roundtripping and possibly with unicode</a></dt>
<dd>

</dd>
</dl>

<h1 id="SUPPORT">SUPPORT</h1>

<p>You can find documentation for this module with the perldoc command.</p>

<pre><code>perldoc Data::Roundtrip</code></pre>

<p>You can also look for information at:</p>

<ul>

<li><p>RT: CPAN&#39;s request tracker (report bugs here)</p>

<p><a href="https://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Roundtrip">https://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Roundtrip</a></p>

</li>
<li><p>AnnoCPAN: Annotated CPAN documentation</p>

<p><a href="http://annocpan.org/dist/Data-Roundtrip">http://annocpan.org/dist/Data-Roundtrip</a></p>

</li>
<li><p>Review this module at PerlMonks</p>

<p><a href="https://www.perlmonks.org/?node_id=21144">https://www.perlmonks.org/?node_id=21144</a></p>

</li>



( run in 1.418 second using v1.01-cache-2.11-cpan-39bf76dae61 )