HTML::Native::JavaScript - embedded JavaScript code
use HTML::Native::JavaScript; my $external_js = HTML::Native::JavaScript->new ( { src => "script.js" } ); print $external_js; # prints "<script src="script.js" type="text/javascript"></script>" my $inline_js = HTML::Native::JavaScript->new ( <<'EOF' ); document.write("<b>Hello World</b>"); EOF print $inline_js; # prints: # <script type="text/javascript">//<![CDATA[ # document.write("<b>Hello World</b>"); # //]]></script>
An HTML::Native::JavaScript object represents a piece of JavaScript code, either external or inline. It generates the <script> tag, and will wrap inline JavaScript code inside //<![CDATA[ and //]]> markers to ensure correct interpretation by both HTML and XHTML parsers.
<script>
//<![CDATA[
//]]>
$elem = HML::Native::JavaScript->new(); $elem = HML::Native::JavaScript->new ( { <attributes> } ); $elem = HML::Native::JavaScript->new ( <inline script> ); $elem = HML::Native::JavaScript->new ( { <attributes> }, <inline script> );
Create a new HTML::Native::JavaScript object, representing a single <script> element.
The attribute type="text/javascript" will be added automatically if not explicitly specified.
type="text/javascript"
To install HTML::Native, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Native
CPAN shell
perl -MCPAN -e shell install HTML::Native
For more information on module installation, please visit the detailed CPAN module installation guide.