Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • ... until it evolves to the point where it can read email.

    People moan at Perl's syntax, and then they embrace XSL. Go figure!

    --
    • Randal L. Schwartz
    • Stonehenge
    • Ha!

      package XML::LibXSLT::Sendmail
      use strict;
      use XML::LibXSLT;
      use Mail::Sendmail;

      XML::LibXSLT->register_function( "http://example.org/mail/", "sendMail", \&xsltmail );

      sub xsltmail {
        my ($to, $from, $body) = @_;
        return sendmail( To => $to, From => $from, Message => $body ); # boolean
      }

      ...then later...

      <xsl:variable name='mailOk' select='mail:sendMail( /doc/meta/author/@email, $from, ../text )'/>
      <xsl:choose>
        <xsl:when test='$mailOk'>
          Mail sent.
        </xsl:when>
        <xsl:otherwise>
          Failed to send mail.
        </xsl:otherwise>
      </xsl:choose>

      But that was the easiest part. Now reading:

      package XML::LibXSLT::Readmail
      use strict;
      use XML::LibXML;
      use XML::LibXSLT;
      use Mail::Internet;
      use Mail::XML;

      XML::LibXSLT->register_function( "http://example.org/mail/", "readMail", \&gotmail );

      sub gotmail {
        # grab mail from account, as usual and turn into $msg Mail::Internet message
        return XML::LibXML->new->parse_string( Mail::XML->new($msg)->toXML );
      }

      ...then later...

        <xsl:apply-templates select='mail:readMail(...params...)'/>

      Scared yet, or do you want to see the MMIX implementation in XSLT [xml.org]? :)

      --

      -- Robin Berjon [berjon.com]