| 1 | package eris::schemas; | ||||||||||
| 2 | # ABSTRACT: Discovery and access for schemas | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | with qw( | |||||||||
| 6 | eris::role::pluggable | ||||||||||
| 7 | ); | ||||||||||
| 8 | 1 | ▶ | use Types::Standard qw(HashRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | our $VERSION = '0.008'; # VERSION | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub _build_namespace { 'eris::schema' } | ||||||||
|
Subroutine
_build_namespace: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | sub find { | ||||||||||
| 20 | 0 | ▶ | my ($self,$log) = @_; | ||||||||
|
Subroutine
find: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 21 | 0 | my @schemas = (); | |||||||||
| 22 | # Otherwise, find the schema's collecting this log | ||||||||||
| 23 | 0 | foreach my $p (@{ $self->plugins }) { | |||||||||
| 24 | # Jump out as quickly as possible | ||||||||||
| 25 | 0 | ▶ | if( $p->match_log($log) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | push @schemas, $p; | |||||||||
| 27 | 0 | ▶ | last if $p->final; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | } | ||||||||||
| 29 | } | ||||||||||
| 30 | # Return our schemas | ||||||||||
| 31 | 0 | return @schemas; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | sub as_bulk { | ||||||||||
| 36 | 0 | ▶ | my ($self,$log) = @_; | ||||||||
|
Subroutine
as_bulk: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 37 | # Find the matching schemas | ||||||||||
| 38 | 0 | my @schemas = $self->find($log); | |||||||||
| 39 | # Return the bulk strings or the empty list | ||||||||||
| 40 | 0 | ▶ | return @schemas ? map { $_->as_bulk($log) } @schemas : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | sub to_document { | ||||||||||
| 45 | 0 | ▶ | my ($self,$log) = @_; | ||||||||
|
Subroutine
to_document: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 46 | # Find the matching schemas | ||||||||||
| 47 | 0 | my @schemas = $self->find($log); | |||||||||
| 48 | # Return the document or the empty list | ||||||||||
| 49 | 0 | ▶ | return @schemas ? $schemas[0]->to_document($log) : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | 1 | 1; | |||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||
| 56 | |||||||||||
| 57 | =pod | ||||||||||
| 58 | |||||||||||
| 59 | =encoding UTF-8 | ||||||||||
| 60 | |||||||||||
| 61 | =head1 NAME | ||||||||||
| 62 | |||||||||||
| 63 | eris::schemas - Discovery and access for schemas | ||||||||||
| 64 | |||||||||||
| 65 | =head1 VERSION | ||||||||||
| 66 | |||||||||||
| 67 | version 0.008 | ||||||||||
| 68 | |||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||
| 70 | |||||||||||
| 71 | use eris::schemas; | ||||||||||
| 72 | use eris::contextualizer; | ||||||||||
| 73 | |||||||||||
| 74 | my $schm = eris::schemas->new(); | ||||||||||
| 75 | my $ctxr = eris::contextualizer->new(); | ||||||||||
| 76 | |||||||||||
| 77 | # Transform each line from STDIN or a file into bulk commands: | ||||||||||
| 78 | while( <<>> ) { | ||||||||||
| 79 | my $log = $ctxr->contextualize( $_ ); | ||||||||||
| 80 | print $schm->as_bulk($log); | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | =head1 ATTRIBUTES | ||||||||||
| 84 | |||||||||||
| 85 | =head2 namespace | ||||||||||
| 86 | |||||||||||
| 87 | Default namespace is 'eris::schema' | ||||||||||
| 88 | |||||||||||
| 89 | =head1 METHODS | ||||||||||
| 90 | |||||||||||
| 91 | =head2 find() | ||||||||||
| 92 | |||||||||||
| 93 | Takes an instance of an L<eris::log> you want to index into ElasticSearch. | ||||||||||
| 94 | |||||||||||
| 95 | Discover all possible, enabled schemas according to the C<search_path> as configured, | ||||||||||
| 96 | find all schemas matching the passed L<eris::log> object. | ||||||||||
| 97 | |||||||||||
| 98 | Returns a list | ||||||||||
| 99 | |||||||||||
| 100 | =head2 as_bulk() | ||||||||||
| 101 | |||||||||||
| 102 | Takes an instance of an L<eris::log> to index into ElasticSearch. | ||||||||||
| 103 | |||||||||||
| 104 | Using the C<find()> method, return a list of the commands necessary to | ||||||||||
| 105 | bulk index the instance of an L<eris::log> object as an array of new-line delimited | ||||||||||
| 106 | JSON. | ||||||||||
| 107 | |||||||||||
| 108 | =head2 to_document() | ||||||||||
| 109 | |||||||||||
| 110 | Takes an instance of an L<eris::log> to index into ElasticSearch. | ||||||||||
| 111 | |||||||||||
| 112 | Using the C<find()> method, return the first document to be created from the | ||||||||||
| 113 | L<eris::log> entry. | ||||||||||
| 114 | |||||||||||
| 115 | =head1 AUTHOR | ||||||||||
| 116 | |||||||||||
| 117 | Brad Lhotsky <brad@divisionbyzero.net> | ||||||||||
| 118 | |||||||||||
| 119 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 120 | |||||||||||
| 121 | This software is Copyright (c) 2015 by Brad Lhotsky. | ||||||||||
| 122 | |||||||||||
| 123 | This is free software, licensed under: | ||||||||||
| 124 | |||||||||||
| 125 | The (three-clause) BSD License | ||||||||||
| 126 | |||||||||||
| 127 | =cut | ||||||||||