| 1 | package eris::dictionary; | ||||||||||
| 2 | # ABSTRACT: Field dictionary loader | ||||||||||
| 3 | |||||||||||
| 4 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | with qw( | |||||||||
| 6 | eris::role::pluggable | ||||||||||
| 7 | ); | ||||||||||
| 8 | 3 | ▶ | use Types::Standard qw(HashRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | our $VERSION = '0.008'; # VERSION | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub _build_namespace { 'eris::dictionary' } | ||||||||
|
Subroutine
_build_namespace: not called CC=1 SCAR=6.9
| |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | 3 | has fields => ( | |||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | isa => HashRef, | ||||||||||
| 21 | lazy => 1, | ||||||||||
| 22 | builder => '_build_fields', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | sub _build_fields { | ||||||||||
| 26 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build_fields: not called CC=4 SCAR=30.0
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | my %complete = (); | |||||||||
| 29 | 0 | foreach my $p ( @{ $self->plugins } ) { | |||||||||
| 30 | 0 | foreach my $f ( @{ $p->fields } ) { | |||||||||
| 31 | 0 | ▶ | if( exists $complete{$f} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | warn sprintf "Duplicated field '%s' in dictionaries, %s authoratitive, %s conflicting.", | ||||||||||
| 33 | $f, | ||||||||||
| 34 | 0 | $complete{$f}, | |||||||||
| 35 | $p->name; | ||||||||||
| 36 | 0 | next; | |||||||||
| 37 | } | ||||||||||
| 38 | 0 | $complete{$f} = $p->name; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | return \%complete; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 3 | my %_dict = (); | |||||||||
| 47 | sub lookup { | ||||||||||
| 48 | 0 | ▶ | my ($self,$field) = @_; | ||||||||
|
Subroutine
lookup: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 49 | 0 | ▶ | return $_dict{$field} if exists $_dict{$field}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | # Otherwise, lookup | ||||||||||
| 52 | 0 | my $entry; | |||||||||
| 53 | 0 | foreach my $p (@{ $self->plugins }) { | |||||||||
| 54 | 0 | $entry = $p->lookup($field); | |||||||||
| 55 | 0 | ▶ | last if defined $entry; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | } | ||||||||||
| 57 | 0 | ▶ | defined $entry ? $_dict{$field} = $entry : undef; # Assignment carries Left to Right and is returned; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | 3 | 1; | |||||||||
| 62 | |||||||||||
| 63 | __END__ | ||||||||||
| 64 | |||||||||||
| 65 | =pod | ||||||||||
| 66 | |||||||||||
| 67 | =encoding UTF-8 | ||||||||||
| 68 | |||||||||||
| 69 | =head1 NAME | ||||||||||
| 70 | |||||||||||
| 71 | eris::dictionary - Field dictionary loader | ||||||||||
| 72 | |||||||||||
| 73 | =head1 VERSION | ||||||||||
| 74 | |||||||||||
| 75 | version 0.008 | ||||||||||
| 76 | |||||||||||
| 77 | =head1 SYNOPSIS | ||||||||||
| 78 | |||||||||||
| 79 | use eris::dictionary; | ||||||||||
| 80 | use YAML; | ||||||||||
| 81 | |||||||||||
| 82 | my $dict = eris::dictionary->new(); | ||||||||||
| 83 | |||||||||||
| 84 | while(<>) { | ||||||||||
| 85 | chomp; | ||||||||||
| 86 | foreach my $word (split /\s+/) { | ||||||||||
| 87 | my $def = $dict->lookup($word); | ||||||||||
| 88 | print Dump $def if $def; | ||||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | =head1 ATTRIBUTES | ||||||||||
| 93 | |||||||||||
| 94 | =head2 namespace | ||||||||||
| 95 | |||||||||||
| 96 | Defaults to C<eris::dictionary> | ||||||||||
| 97 | |||||||||||
| 98 | =head2 fields | ||||||||||
| 99 | |||||||||||
| 100 | HashRef of fields with true/false values indicated whether they exist in the dictionary. | ||||||||||
| 101 | |||||||||||
| 102 | =head1 METHODS | ||||||||||
| 103 | |||||||||||
| 104 | =head2 lookup | ||||||||||
| 105 | |||||||||||
| 106 | Takes a field name, returns the entry for that field from | ||||||||||
| 107 | the first matching dictionary or undef if nothing is found | ||||||||||
| 108 | |||||||||||
| 109 | =head1 SEE ALSO | ||||||||||
| 110 | |||||||||||
| 111 | L<eris::role::dictionary>, L<eris::dictionary::cee>, L<eris::dictionary::eris>, | ||||||||||
| 112 | L<eris::dictionary::eris::debug>, L<eris::dictionary::syslog> | ||||||||||
| 113 | |||||||||||
| 114 | =head1 AUTHOR | ||||||||||
| 115 | |||||||||||
| 116 | Brad Lhotsky <brad@divisionbyzero.net> | ||||||||||
| 117 | |||||||||||
| 118 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 119 | |||||||||||
| 120 | This software is Copyright (c) 2015 by Brad Lhotsky. | ||||||||||
| 121 | |||||||||||
| 122 | This is free software, licensed under: | ||||||||||
| 123 | |||||||||||
| 124 | The (three-clause) BSD License | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||