Pygmentsをperlで使いたかったので、 Inline::Pythonでやってみた。
use Inline Python => <<'END_OF_PYTHON_CODE';
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
def py_highlight(code):
return highlight(code, PythonLexer(), HtmlFormatter())
def get_stylesheet():
return HtmlFormatter().get_style_defs('.highlight')
END_OF_PYTHON_CODE
$code = <<'PYTHON_CODE';
from reportlab.pdfgen import canvas
c = canvas.Canvas('hello.pdf')
t = c.beginText()
t.setFont(t._fontname, 64)
t.setTextOrigin(0, 0)
t.textOut('Hello, World')
h = 64 / t.getX() * c._pagesize[1]
t.setFont(t._fontname, h)
c.setFontSize(h)
c.rotate(-90)
c.drawString(-c._pagesize[1], t._leading - h, 'Hello, World')
c.save()
PYTHON_CODE
printf qq|<html><head><style type="text/css">%s</style>
</head>\n<body>%s</body>\n</html>|, get_stylesheet(), py_highlight($code);