| 1 | package Sentry::Stacktrace::Frame; | ||
| 2 | use Mojo::Base -base, -signatures; | ||
| 3 | |||
| 4 | use Mojo::Home; | ||
| 5 | |||
| 6 | has [qw(package filename line subroutine)]; | ||
| 7 | has _source_file_registry => sub { Sentry::SourceFileRegistry->new }; | ||
| 8 | has _home => sub { Mojo::Home->new->detect }; | ||
| 9 | |||
| 10 | sub _is_in_app ($self) { | ||
| 11 | return $self->filename !~ /\.cpan/ | ||
| 12 | && index($self->filename, $self->_home) > -1; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub _map_file_to_context ($self) { | ||
| 16 | return $self->_source_file_registry->get_context_lines($self->filename, | ||
| 17 | $self->line); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub TO_JSON ($self) { | ||
| 21 | return { | ||
| 22 | in_app => \($self->_is_in_app()), | ||
| 23 | abs_path => $self->filename, | ||
| 24 | file_name => 'bla', | ||
| 25 | lineno => $self->line, | ||
| 26 | package => $self->package, | ||
| 27 | function => $self->subroutine, | ||
| 28 | %{ $self->_map_file_to_context() }, | ||
| 29 | }; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub from_caller ($package, $pkg, $filename, $line, $subroutine, @args) { | ||
| 33 | return $package->new({ | ||
| 34 | package => $pkg, | ||
| 35 | filename => $filename, | ||
| 36 | line => $line, | ||
| 37 | subroutine => $subroutine | ||
| 38 | }); | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; |