| 1 | package Sentry::SourceFileRegistry; | ||
| 2 | use Mojo::Base -base, -signatures; | ||
| 3 | |||
| 4 | use Mojo::File; | ||
| 5 | use Mojo::Util 'dumper'; | ||
| 6 | use Sentry::Cache; | ||
| 7 | use Sentry::SourceFileRegistry::ContextLine; | ||
| 8 | |||
| 9 | has _cache => sub { Sentry::Cache->get_instance }; | ||
| 10 | |||
| 11 | sub _get_cached_context_line ($self, $file) { | ||
| 12 | my $context = $self->_cache->get($file); | ||
| 13 | |||
| 14 | if (!$context) { | ||
| 15 | my $content = Mojo::File->new($file)->slurp; | ||
| 16 | $context | ||
| 17 | = Sentry::SourceFileRegistry::ContextLine->new(content => $content); | ||
| 18 | $self->_cache->set($file, $context); | ||
| 19 | } | ||
| 20 | |||
| 21 | return $context; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub get_context_lines ($self, $file, $line) { | ||
| 25 | return $self->_get_cached_context_line($file)->get($line); | ||
| 26 | } | ||
| 27 | |||
| 28 | 1; |