The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Locale::TextDomain::OO::Lexicon::StoreJSON - Stores the lexicon for other programming languages

$Id: StoreJSON.pm 647 2017-02-25 08:22:10Z steffenw $

$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Lexicon/StoreJSON.pm $

VERSION

1.026

DESCRIPTION

This module stores the lexicon for other programming language e.g. JavaScript.

SYNOPSIS

write file by given filename

    use Locale::TextDomain::OO::Lexicon::StoreJSON;

    Locale::TextDomain::OO::Lexicon::StoreJSON
        ->new(
            filename => 'my_json_file',
            ...
        )
        ->to_json; # ->to_javascript or ->to_html

write file by given open file_handle

    use Carp qw(confess);
    use IO::File;
    use Locale::TextDomain::OO::Lexicon::StoreJSON;

    my $filename = 'my_json_file';
    my $file_handle = IO::File->new( $filename, q{>} )
        or confess qq{Unable to open file "$filename" $!};
    Locale::TextDomain::OO::Lexicon::StoreJSON
        ->new(
            filename    => $filename, # optional for error message only
            file_handle => file_handle,
            ...
        )
        ->to_json; # ->to_javascript or ->to_html
    $file_handle->close
        or confess qq{Unable to close file "$filename" $!};

as string

    use Locale::TextDomain::OO::Lexicon::StoreJSON;

    my $json = Locale::TextDomain::OO::Lexicon::StoreJSON
        ->new(
            ...
        )
        ->to_json; # ->to_javascript or ->to_html

optional filter

    use Locale::TextDomain::OO::Lexicon::StoreJSON;

    my $json = Locale::TextDomain::OO::Lexicon::StoreJSON->new(
        ...
        # all parameters optional
        # with all type examples for filter_... attributes
        filter_language => undef,                       # default, means all
        filter_domain   => 'my domain',                 # string
        filter_category => qr{ \A \Qmy category\E }xms, # regex
        filter_project  => sub {                        # code reference
            my $filter_name = shift;   # is 'filter_project'
            return $_ eq 'my project'; # boolean return
        },
    );
    # from lexicon to data
    # method to_json will use data to output
    $json->copy;
    $json->clear_filter; # set all filter_... to undef
    $json->filter_domain( qr{ \A dom }xms );
    $json->copy;
    $json->clear_filter;
    $json->filter_category( sub { return $_ eq 'cat1' } );
    $json->copy;
    $json->clear_filter;
    $json->filter_domain('dom1');
    $json->filter_category('cat1');
    # remove all lexicons with dom1 and cat1 from data
    $json->remove;
    $json->to_json; # ->to_javascript or ->to_html

SUBROUTINES/METHODS

method new

see SYNOPSIS

method to_json

With file parameters it prints a JSON file. Otherwise returns a JSON string.

method to_javascript

Similar to method to_json but output wrapped as JavaScript with global variable "localeTextDomainOOLexicon".

method to_html

Similar to method to_javascript but output wrapped as HTML with script tag.

EXAMPLE

Inside of this distribution is a directory named example. Run this *.pl files.

DIAGNOSTICS

none

CONFIGURATION AND ENVIRONMENT

none

DEPENDENCIES

JSON

Moo

MooX::StrictConstructor

namespace::autoclean

Locale::TextDomain::OO::Lexicon::Role::StoreFile

Locale::TextDomain::OO::Lexicon::Role::StoreFilter

INCOMPATIBILITIES

not known

BUGS AND LIMITATIONS

none

SEE ALSO

Locale::TextDoamin::OO

AUTHOR

Steffen Winkler

LICENSE AND COPYRIGHT

Copyright (c) 2013 - 2014, Steffen Winkler <steffenw at cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.