NAME
Carp::SyntaxHighlightSource - Die/warn of errors with stack backtrace and source context
VERSION
This document describes version 0.03 of Carp::SyntaxHighlightSource (from Perl distribution Carp-Always-SyntaxHighlightSource), released on 2016-03-16.
SYNOPSIS
use Carp::SyntaxHighlightSource 'source_cluck';
source_cluck 'some error';
source_cluck 'some error',
lines => 5, number => 0, color => 'yellow on_blue';
DESCRIPTION
This module exports one function, source_cluck()
, which prints stack traces with syntax-highlighted source code extracts to make it obvious what has been called from where.
It does not work for one-liners because there is no file from which to load source code.
Syntax-highlighting is done using SyntaxHighlight::Any. You need one or more backends for syntax-highlighting to work, e.g. B,Pygments> or GNU source-highlight.
- source_cluck
-
source_cluck 'some error'; source_cluck 'some error', lines => 5, number => 0, color => 'yellow on_blue';
Like Carp's
cluck()
, but it also displays the source code context of all call frames, with three lines before and after each call being shown, and the call being highlighted.It takes as arguments a string (the error message) and a hash of options. The following options are recognized:
- lines
-
Number of lines to display before and after the line reported in the stack trace. Defaults to 3.
- number
-
Boolean value to indicate whether line numbers should be printed at the beginning of the context source code lines. Defaults to yes.
- color
-
The color in which to print the source code line reported in the stack trace. It has to be a string that Term::ANSIColor understands. Defaults to
black on_yellow
.
This is just a quick hack - not all of
Carp
's or even justcluck()
's features are present. The code borrows heavily fromCarp
.
CREDITS
Modified from Carp::Source.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Carp-Always-SyntaxHighlightSource.
SOURCE
Source repository is at https://github.com/sharyanto/perl-Carp-Always-SyntaxHighlightSource.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Carp-Always-SyntaxHighlightSource
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
Carp::Always::SyntaxHighlightSource
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.