Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

use HTML; # !!!

by japhy (Canon)
on Jul 26, 2002 at 17:26 UTC ( #185604=snippet: print w/ replies, xml ) Need Help??

Description: Embed HTML directly into your Perl code. Just be sure you're using warnings.
package HTML;

$SIG{__WARN__} = sub {
  if ($_[0] =~ /readline\(\) on unopened filehandle (\S+)/) {
    print "<$1>";
  }
  elsif ($_[0] !~ /only once/) { warn @_ }
};

sub import {
  my $pkg = caller;
  *{ $pkg . "::glob" } = \&tag;
}

sub tag {
  my $tag = shift;
  $tag =~ s/\s+$//;
  wantarray ? "<$tag>" : print "<$tag>";
}

1;

__END__
#!/usr/bin/perl -w
use HTML;

print
  <html>,
  <head>,
    <title>, "This is vile", </title>,
  </head>,
  <body bgcolor="#ffffaa">,
  <tt>, "japhy", </tt>, " is insane.",
  </body>,
  </html>,
;
Comment on use HTML; # !!!
Download Code
Re: use HTML; # !!!
by dws (Chancellor) on Jul 26, 2002 at 17:38 UTC
    use HTML; print <aol>, "that's sick! :)", </aol>;
      Agreed, sick sick SICK!!

      ...I love it.

Re: use HTML; # !!!
by dragonchild (Archbishop) on Jul 26, 2002 at 18:51 UTC
    Mod needed for 5.005_3:
    if ($_[0] =~ /readline\(\) on unopened filehandle (\S+)/ || $_[0] =~ /Read on (?:unopened|closed) filehandle <(\S+)>/ ) {

    Way cool!

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: use HTML; # !!!
by RMGir (Prior) on Jul 26, 2002 at 21:18 UTC
    You're already being really evil by writing this (or using it!), so what's a bit of anti-social coding?
    package HTML; #force warnings on, in case user "forgot" to... :) $^W++; # rest exactly as japhy wrote it

    --
    Mike
Re: use HTML; # !!!
by BrowserUk (Pope) on Jul 26, 2002 at 21:33 UTC

    Evil? Maybe...but it beats the pants off of CGI poetry mode.


    <itsy-bitsy-tiny>Is this really so evil? Or am I just too (dumb|new|unperlish) to see the dangers?</itsy-bitsy-tiny>
Re: use HTML; # !!!
by Anonymous Monk on Jul 28, 2002 at 22:55 UTC
    Move the $SIG{__WARN__} setting into import and have a sub unimport { delete $SIG{__WARN__} } (untested)
Re: use HTML; # !!!
by strfry() (Monk) on Aug 05, 2002 at 19:15 UTC
    this has an interesting side effect, such as evidenced in this one-liner: perl -MHTML -e 'use warnings;use CGI qw/:cgi/; my $cgi = new CGI; print $cgi->header(-type => "text/html"),<html>,<head>,<title>,"Yuck",</title>,</head>,<body>,<tt>,"hello world",</tt>,</body>,</html>, "\n";' in order to get this to work as it should, i'm forced to make two separate print calls.

    whether this (bug|feature) makes this module more or less evil is best left to your discretion. (:

    strfry()

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://185604]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2014-08-28 14:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (263 votes), past polls