carp and croak traverse the values returned by the caller() builtin function (see perldoc -f caller).
in reply to line number
The code inside the Carp module is pretty hairy stuff, but it makes for interesting reading. I found the most interesting parts were the sections of code added so that the warning was issued in the code outside the package -- or any child or parent package -- so that OO Perl still works. Neat stuff.
Added:The Carp code travels up the call stack (via caller()) until it finds the first routine that calls itself that isn't in the current package (or one of its relatives, so that method inheritance works).