.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Loader 3pm" .TH Mojo::Loader 3pm "2019-02-05" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Loader \- Load all kinds of things .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Loader qw(data_section find_modules load_class); \& \& # Find modules in a namespace \& for my $module (find_modules \*(AqSome::Namespace\*(Aq) { \& \& # Load them safely \& my $e = load_class $module; \& warn qq{Loading "$module" failed: $e} and next if ref $e; \& \& # And extract files from the DATA section \& say data_section($module, \*(Aqsome_file.txt\*(Aq); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Loader is a class loader and plugin framework. Aside from finding modules and loading classes, it allows multiple files to be stored in the \&\f(CW\*(C`DATA\*(C'\fR section of a class, which can then be accessed individually. .PP .Vb 1 \& package Foo; \& \& 1; \& _\|_DATA_\|_ \& \& @@ test.txt \& This is the first file. \& \& @@ test2.html (base64) \& VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUu \& \& @@ test \& This is the \& third file. .Ve .PP Each file has a header starting with \f(CW\*(C`@@\*(C'\fR, followed by the file name and optional instructions for decoding its content. Currently only the Base64 encoding is supported, which can be quite convenient for the storage of binary data. .SH "FUNCTIONS" .IX Header "FUNCTIONS" Mojo::Loader implements the following functions, which can be imported individually. .SS "data_section" .IX Subsection "data_section" .Vb 2 \& my $all = data_section \*(AqFoo::Bar\*(Aq; \& my $index = data_section \*(AqFoo::Bar\*(Aq, \*(Aqindex.html\*(Aq; .Ve .PP Extract embedded file from the \f(CW\*(C`DATA\*(C'\fR section of a class, all files will be cached once they have been accessed for the first time. .PP .Vb 2 \& # List embedded files \& say for keys %{data_section \*(AqFoo::Bar\*(Aq}; .Ve .SS "file_is_binary" .IX Subsection "file_is_binary" .Vb 1 \& my $bool = file_is_binary \*(AqFoo::Bar\*(Aq, \*(Aqtest.png\*(Aq; .Ve .PP Check if embedded file from the \f(CW\*(C`DATA\*(C'\fR section of a class was Base64 encoded. .SS "find_packages" .IX Subsection "find_packages" .Vb 1 \& my @pkgs = find_packages \*(AqMyApp::Namespace\*(Aq; .Ve .PP Search for packages in a namespace non-recursively. .SS "find_modules" .IX Subsection "find_modules" .Vb 1 \& my @modules = find_modules \*(AqMyApp::Namespace\*(Aq; .Ve .PP Search for modules in a namespace non-recursively. .SS "load_class" .IX Subsection "load_class" .Vb 1 \& my $e = load_class \*(AqFoo::Bar\*(Aq; .Ve .PP Load a class and catch exceptions, returns a false value if loading was successful, a true value if the class was not found, or a Mojo::Exception object if loading failed. Note that classes are checked for a \f(CW\*(C`new\*(C'\fR method to see if they are already loaded, so trying to load the same class multiple times may yield different results. .PP .Vb 4 \& # Handle exceptions \& if (my $e = load_class \*(AqFoo::Bar\*(Aq) { \& die ref $e ? "Exception: $e" : \*(AqNot found!\*(Aq; \& } .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .