{
    "content": [
        {
            "type": "text",
            "text": "# Carp (man)\n\n## NAME\n\nCarp - alternative warn and die for modules\n\n## SYNOPSIS\n\nuse Carp;\n# warn user (from perspective of caller)\ncarp \"string trimmed to 80 chars\";\n# die of errors (from perspective of caller)\ncroak \"We're outta here!\";\n# die of errors with stack backtrace\nconfess \"not implemented\";\n# cluck, longmess and shortmess not exported by default\nuse Carp qw(cluck longmess shortmess);\ncluck \"This is how we got here!\"; # warn with stack backtrace\n$longmessage   = longmess( \"message from cluck() or confess()\" );\n$shortmessage  = shortmess( \"message from carp() or croak()\" );\n\n## DESCRIPTION\n\nThe Carp routines are useful in your own modules because they act like \"die()\" or \"warn()\",\nbut with a message which is more likely to be useful to a user of your module.  In the case\nof \"cluck()\" and \"confess()\", that context is a summary of every call in the call-stack;\n\"longmess()\" returns the contents of the error message.\n\n## TLDR\n\n> REPL and build tool for Carp.\n\n- Start a REPL (interactive shell):\n  `carp`\n- Start a REPL with a custom prompt:\n  `carp --prompt \"{{> }}\"`\n- Build a `carp` file:\n  `carp -b {{path/to/file.carp}}`\n- Build and run a file:\n  `carp -x {{path/to/file.carp}}`\n- Build a file with optimizations enabled:\n  `carp -b --optimize {{path/to/file.carp}}`\n- Transpile a file to C code:\n  `carp --generate-only {{path/to/file.carp}}`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (2 subsections)\n- **GLOBAL VARIABLES** (8 subsections)\n- **BUGS**\n- **SEE ALSO**\n- **CONTRIBUTING**\n- **AUTHOR**\n- **COPYRIGHT**\n- **LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Carp",
        "section": "",
        "mode": "man",
        "summary": "Carp - alternative warn and die for modules",
        "synopsis": "use Carp;\n# warn user (from perspective of caller)\ncarp \"string trimmed to 80 chars\";\n# die of errors (from perspective of caller)\ncroak \"We're outta here!\";\n# die of errors with stack backtrace\nconfess \"not implemented\";\n# cluck, longmess and shortmess not exported by default\nuse Carp qw(cluck longmess shortmess);\ncluck \"This is how we got here!\"; # warn with stack backtrace\n$longmessage   = longmess( \"message from cluck() or confess()\" );\n$shortmessage  = shortmess( \"message from carp() or croak()\" );",
        "tldr_summary": "REPL and build tool for Carp.",
        "tldr_examples": [
            {
                "description": "Start a REPL (interactive shell)",
                "command": "carp"
            },
            {
                "description": "Start a REPL with a custom prompt",
                "command": "carp --prompt \"{{> }}\""
            },
            {
                "description": "Build a `carp` file",
                "command": "carp -b {{path/to/file.carp}}"
            },
            {
                "description": "Build and run a file",
                "command": "carp -x {{path/to/file.carp}}"
            },
            {
                "description": "Build a file with optimizations enabled",
                "command": "carp -b --optimize {{path/to/file.carp}}"
            },
            {
                "description": "Transpile a file to C code",
                "command": "carp --generate-only {{path/to/file.carp}}"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 43,
                "subsections": [
                    {
                        "name": "Forcing a Stack Trace",
                        "lines": 15
                    },
                    {
                        "name": "Stack Trace formatting",
                        "lines": 21
                    }
                ]
            },
            {
                "name": "GLOBAL VARIABLES",
                "lines": 1,
                "subsections": [
                    {
                        "name": "$Carp::MaxEvalLen",
                        "lines": 5
                    },
                    {
                        "name": "$Carp::MaxArgLen",
                        "lines": 5
                    },
                    {
                        "name": "$Carp::MaxArgNums",
                        "lines": 5
                    },
                    {
                        "name": "$Carp::Verbose",
                        "lines": 5
                    },
                    {
                        "name": "$Carp::RefArgFormatter",
                        "lines": 47
                    },
                    {
                        "name": "%Carp::Internal",
                        "lines": 10
                    },
                    {
                        "name": "%Carp::CarpInternal",
                        "lines": 10
                    },
                    {
                        "name": "$Carp::CarpLevel",
                        "lines": 14
                    }
                ]
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "CONTRIBUTING",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Carp - alternative warn and die for modules\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Carp;\n\n# warn user (from perspective of caller)\ncarp \"string trimmed to 80 chars\";\n\n# die of errors (from perspective of caller)\ncroak \"We're outta here!\";\n\n# die of errors with stack backtrace\nconfess \"not implemented\";\n\n# cluck, longmess and shortmess not exported by default\nuse Carp qw(cluck longmess shortmess);\ncluck \"This is how we got here!\"; # warn with stack backtrace\n$longmessage   = longmess( \"message from cluck() or confess()\" );\n$shortmessage  = shortmess( \"message from carp() or croak()\" );\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The Carp routines are useful in your own modules because they act like \"die()\" or \"warn()\",\nbut with a message which is more likely to be useful to a user of your module.  In the case\nof \"cluck()\" and \"confess()\", that context is a summary of every call in the call-stack;\n\"longmess()\" returns the contents of the error message.\n\nFor a shorter message you can use \"carp()\" or \"croak()\" which report the error as being from\nwhere your module was called.  \"shortmess()\" returns the contents of this error message.\nThere is no guarantee that that is where the error was, but it is a good educated guess.\n\n\"Carp\" takes care not to clobber the status variables $! and $^E in the course of assembling\nits error messages.  This means that a $SIG{DIE} or $SIG{WARN} handler can capture\nthe error information held in those variables, if it is required to augment the error\nmessage, and if the code calling \"Carp\" left useful values there.  Of course, \"Carp\" can't\nguarantee the latter.\n\nYou can also alter the way the output and logic of \"Carp\" works, by changing some global\nvariables in the \"Carp\" namespace. See the section on \"GLOBAL VARIABLES\" below.\n\nHere is a more complete description of how \"carp\" and \"croak\" work.  What they do is search\nthe call-stack for a function call stack where they have not been told that there shouldn't\nbe an error.  If every call is marked safe, they give up and give a full stack backtrace\ninstead.  In other words they presume that the first likely looking potential suspect is\nguilty.  Their rules for telling whether a call shouldn't generate errors work as follows:\n\n1.  Any call from a package to itself is safe.\n\n2.  Packages claim that there won't be errors on calls to or from packages explicitly marked\nas safe by inclusion in @CARPNOT, or (if that array is empty) @ISA.  The ability to\noverride what @ISA says is new in 5.8.\n\n3.  The trust in item 2 is transitive.  If A trusts B, and B trusts C, then A trusts C.  So\nif you do not override @ISA with @CARPNOT, then this trust relationship is identical to,\n\"inherits from\".\n\n4.  Any call from an internal Perl module is safe.  (Nothing keeps user modules from marking\nthemselves as internal to Perl, but this practice is discouraged.)\n\n5.  Any call to Perl's warning system (eg Carp itself) is safe.  (This rule is what keeps it\nfrom reporting the error at the point where you call \"carp\" or \"croak\".)\n\n6.  $Carp::CarpLevel can be set to skip a fixed number of additional call levels.  Using this\nis not recommended because it is very difficult to get it to behave correctly.\n",
                "subsections": [
                    {
                        "name": "Forcing a Stack Trace",
                        "content": "As a debugging aid, you can force Carp to treat a croak as a confess and a carp as a cluck\nacross all modules. In other words, force a detailed stack trace to be given.  This can be\nvery helpful when trying to understand why, or from where, a warning or error is being\ngenerated.\n\nThis feature is enabled by 'importing' the non-existent symbol 'verbose'. You would typically\nenable it by saying\n\nperl -MCarp=verbose script.pl\n\nor by including the string \"-MCarp=verbose\" in the PERL5OPT environment variable.\n\nAlternately, you can set the global variable $Carp::Verbose to true.  See the \"GLOBAL\nVARIABLES\" section below.\n"
                    },
                    {
                        "name": "Stack Trace formatting",
                        "content": "At each stack level, the subroutine's name is displayed along with its parameters.  For\nsimple scalars, this is sufficient.  For complex data types, such as objects and other\nreferences, this can simply display 'HASH(0x1ab36d8)'.\n\nCarp gives two ways to control this.\n\n1.  For objects, a method, \"CARPTRACE\", will be called, if it exists.  If this method\ndoesn't exist, or it recurses into \"Carp\", or it otherwise throws an exception, this is\nskipped, and Carp moves on to the next option, otherwise checking stops and the string\nreturned is used.  It is recommended that the object's type is part of the string to make\ndebugging easier.\n\n2.  For any type of reference, $Carp::RefArgFormatter is checked (see below).  This variable\nis expected to be a code reference, and the current parameter is passed in.  If this\nfunction doesn't exist (the variable is undef), or it recurses into \"Carp\", or it\notherwise throws an exception, this is skipped, and Carp moves on to the next option,\notherwise checking stops and the string returned is used.\n\n3.  Otherwise, if neither \"CARPTRACE\" nor $Carp::RefArgFormatter is available, stringify the\nvalue ignoring any overloading.\n"
                    }
                ]
            },
            "GLOBAL VARIABLES": {
                "content": "",
                "subsections": [
                    {
                        "name": "$Carp::MaxEvalLen",
                        "content": "This variable determines how many characters of a string-eval are to be shown in the output.\nUse a value of 0 to show all text.\n\nDefaults to 0.\n"
                    },
                    {
                        "name": "$Carp::MaxArgLen",
                        "content": "This variable determines how many characters of each argument to a function to print. Use a\nvalue of 0 to show the full length of the argument.\n\nDefaults to 64.\n"
                    },
                    {
                        "name": "$Carp::MaxArgNums",
                        "content": "This variable determines how many arguments to each function to show.  Use a false value to\nshow all arguments to a function call.  To suppress all arguments, use \"-1\" or '0 but true'.\n\nDefaults to 8.\n"
                    },
                    {
                        "name": "$Carp::Verbose",
                        "content": "This variable makes \"carp()\" and \"croak()\" generate stack backtraces just like \"cluck()\" and\n\"confess()\".  This is how \"use Carp 'verbose'\" is implemented internally.\n\nDefaults to 0.\n"
                    },
                    {
                        "name": "$Carp::RefArgFormatter",
                        "content": "This variable sets a general argument formatter to display references.  Plain scalars and\nobjects that implement \"CARPTRACE\" will not go through this formatter.  Calling \"Carp\" from\nwithin this function is not supported.\n\nlocal $Carp::RefArgFormatter = sub {\nrequire Data::Dumper;\nData::Dumper->Dump($[0]); # not necessarily safe\n};\n\n@CARPNOT\nThis variable, in your package, says which packages are not to be considered as the location\nof an error. The \"carp()\" and \"cluck()\" functions will skip over callers when reporting where\nan error occurred.\n\nNB: This variable must be in the package's symbol table, thus:\n\n# These work\nour @CARPNOT; # file scope\nuse vars qw(@CARPNOT); # package scope\n@My::Package::CARPNOT = ... ; # explicit package variable\n\n# These don't work\nsub xyz { ... @CARPNOT = ... } # w/o declarations above\nmy @CARPNOT; # even at top-level\n\nExample of use:\n\npackage My::Carping::Package;\nuse Carp;\nour @CARPNOT;\nsub bar     { .... or error('Wrong input') }\nsub error  {\n# temporary control of where'ness, PACKAGE is implicit\nlocal @CARPNOT = qw(My::Friendly::Caller);\ncarp(@)\n}\n\nThis would make \"Carp\" report the error as coming from a caller not in\n\"My::Carping::Package\", nor from \"My::Friendly::Caller\".\n\nAlso read the \"DESCRIPTION\" section above, about how \"Carp\" decides where the error is\nreported from.\n\nUse @CARPNOT, instead of $Carp::CarpLevel.\n\nOverrides \"Carp\"'s use of @ISA.\n"
                    },
                    {
                        "name": "%Carp::Internal",
                        "content": "This says what packages are internal to Perl.  \"Carp\" will never report an error as being\nfrom a line in a package that is internal to Perl.  For example:\n\n$Carp::Internal{ (PACKAGE) }++;\n# time passes...\nsub foo { ... or confess(\"whatever\") };\n\nwould give a full stack backtrace starting from the first caller outside of PACKAGE.\n(Unless that package was also internal to Perl.)\n"
                    },
                    {
                        "name": "%Carp::CarpInternal",
                        "content": "This says which packages are internal to Perl's warning system.  For generating a full stack\nbacktrace this is the same as being internal to Perl, the stack backtrace will not start\ninside packages that are listed in %Carp::CarpInternal.  But it is slightly different for the\nsummary message generated by \"carp\" or \"croak\".  There errors will not be reported on any\nlines that are calling packages in %Carp::CarpInternal.\n\nFor example \"Carp\" itself is listed in %Carp::CarpInternal.  Therefore the full stack\nbacktrace from \"confess\" will not start inside of \"Carp\", and the short message from calling\n\"croak\" is not placed on the line where \"croak\" was called.\n"
                    },
                    {
                        "name": "$Carp::CarpLevel",
                        "content": "This variable determines how many additional call frames are to be skipped that would not\notherwise be when reporting where an error occurred on a call to one of \"Carp\"'s functions.\nIt is fairly easy to count these call frames on calls that generate a full stack backtrace.\nHowever it is much harder to do this accounting for calls that generate a short message.\nUsually people skip too many call frames.  If they are lucky they skip enough that \"Carp\"\ngoes all of the way through the call stack, realizes that something is wrong, and then\ngenerates a full stack backtrace.  If they are unlucky then the error is reported from\nsomewhere misleading very high in the call stack.\n\nTherefore it is best to avoid $Carp::CarpLevel.  Instead use @CARPNOT, %Carp::Internal and\n%Carp::CarpInternal.\n\nDefaults to 0.\n"
                    }
                ]
            },
            "BUGS": {
                "content": "The Carp routines don't handle exception objects currently.  If called with a first argument\nthat is a reference, they simply call die() or warn(), as appropriate.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Carp::Always, Carp::Clan\n",
                "subsections": []
            },
            "CONTRIBUTING": {
                "content": "Carp is maintained by the perl 5 porters as part of the core perl 5 version control\nrepository. Please see the perlhack perldoc for how to submit patches and contribute to it.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "The Carp module first appeared in Larry Wall's perl 5.000 distribution.  Since then it has\nbeen modified by several of the perl 5 porters.  Andrew Main (Zefram) <zefram@fysh.org>\ndivested Carp into an independent distribution.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (C) 1994-2013 Larry Wall\n\nCopyright (C) 2011, 2012, 2013 Andrew Main (Zefram) <zefram@fysh.org>\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "This module is free software; you can redistribute it and/or modify it under the same terms\nas Perl itself.\n\n\n\nperl v5.34.0                                 2025-07-25                                  Carp(3perl)",
                "subsections": []
            }
        }
    }
}