| 1 | package Mojo::BaseUtil; | ||
| 2 | |||
| 3 | # Only using pure Perl as the only purpose of this module is to break a circular dependency involving Mojo::Base | ||
| 4 | 73 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 73 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 73 | ▶ | use feature ':5.16'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 73 | ▶ | use Exporter qw(import); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 73 | ▶ | use Sub::Util qw(set_subname); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 73 | our @EXPORT_OK = (qw(class_to_path monkey_patch)); | |
| 12 | |||
| 13 | 643 | ▶ | sub class_to_path { join '.', join('/', split(/::|'/, shift)), 'pm' } |
|
Subroutine
class_to_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 14 | |||
| 15 | 27844 | ▶ | sub monkey_patch { |
|
Subroutine
monkey_patch: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 16 | 27844 | my ($class, %patch) = @_; | |
| 17 | 73 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 73 | ▶ | no warnings 'redefine'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 27844 | *{"${class}::$_"} = set_subname("${class}::$_", $patch{$_}) for keys %patch; | |
| 20 | } | ||
| 21 | |||
| 22 | 73 | 1; | |
| 23 | |||
| 24 | =encoding utf8 | ||
| 25 | |||
| 26 | =head1 NAME | ||
| 27 | |||
| 28 | Mojo::BaseUtil - Common utility functions used in Mojo::Base, re-exported in Mojo::Util | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | use Mojo::BaseUtil qw(class_to_path monkey_patch); | ||
| 33 | |||
| 34 | my $path = class_to_path 'Foo::Bar'; | ||
| 35 | monkey_patch 'MyApp', foo => sub { say 'Foo!' }; | ||
| 36 | |||
| 37 | =head1 DESCRIPTION | ||
| 38 | |||
| 39 | L<Mojo::BaseUtil> provides functions to both L<Mojo::Base> and L<Mojo::Util>, so that C<Mojo::Base> does not have to | ||
| 40 | load the rest of L<Mojo::Util>, while preventing a circular dependency. | ||
| 41 | |||
| 42 | =head1 SEE ALSO | ||
| 43 | |||
| 44 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||
| 45 | |||
| 46 | =cut | ||