nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to make use of the bit flags documented at Text::Markdown::Hoedown. I've got the following function, which works, except for the extensions value. I don't know what I'm doing there.

package Dancer2::Plugin::MarkdownFilesToHTML::MarkdownParser ; use strict; use warnings; use parent qw(Exporter); our @EXPORT = qw( markdown ); use XSLoader; XSLoader::load('Text::Markdown::Hoedown', '1.02'); sub markdown { my $str = shift; my %args = ( html_options => 0, extensions => '| HOEDOWN_EXT_FENCED_CODE', max_nesting => 16, toc_nesting_lvl => 99, @_, ); my $renderer = Text::Markdown::Hoedown::Renderer::HTML->new( $args{html_options}, $args{toc_nesting_lvl}, ); my $md = Text::Markdown::Hoedown::Markdown->new( $args{extensions}, $args{max_nesting}, $renderer ); return $md->render($str); }

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: How do you pass bit flag arguments?
by choroba (Cardinal) on Nov 05, 2018 at 21:16 UTC
    The flags are constants, not strings. The | operator is used to combine them, you don't need it if there's only one flag.
    extensions => HOEDOWN_EXT_FENCED_CODE,
    or
    extensions => HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_UNDERLINE,
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Ah, yup. Worked. I should have guessed and tried it as a constant as it's all uppercase. Was scratching my head, though, over how the constant got loaded. I guess by XSLoader.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks