| 1 | package FindApp::Utils::Objects; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 6 | ▶ | use v5.10; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 6 | ▶ | use FindApp::Vars qw( :all ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 6 | ▶ | use FindApp::Utils::Foreign qw( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | blessed | ||||||||||||||
| 10 | pp | ||||||||||||||
| 11 | reftype | ||||||||||||||
| 12 | refaddr | ||||||||||||||
| 13 | 6 | ); | |||||||||||||
| 14 | |||||||||||||||
| 15 | ################################################################# | ||||||||||||||
| 16 | |||||||||||||||
| 17 | sub as_number ( $ ) ; | ||||||||||||||
| 18 | sub as_string ( $ ) ; | ||||||||||||||
| 19 | sub class_prune ( _ ) ; | ||||||||||||||
| 20 | sub myself ; | ||||||||||||||
| 21 | sub op_equals ( $$$ ) ; | ||||||||||||||
| 22 | sub op_notequals ( $$$ ) ; | ||||||||||||||
| 23 | sub pkg_abbr ( $ ) ; | ||||||||||||||
| 24 | |||||||||||||||
| 25 | ################################################################# | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 6 | ▶ | use Exporter qw(import); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 28 | 6 | our $VERSION = v1.0; | |||||||||||||
| 29 | 6 | our @EXPORT_OK = qw( | |||||||||||||
| 30 | as_number | ||||||||||||||
| 31 | as_string | ||||||||||||||
| 32 | class_prune | ||||||||||||||
| 33 | myself | ||||||||||||||
| 34 | op_equals | ||||||||||||||
| 35 | op_notequals | ||||||||||||||
| 36 | pkg_abbr | ||||||||||||||
| 37 | |||||||||||||||
| 38 | ); | ||||||||||||||
| 39 | 6 | our %EXPORT_TAGS = ( | |||||||||||||
| 40 | all => \@EXPORT_OK, | ||||||||||||||
| 41 | overload => [ grep /^(?:as|op)_/, @EXPORT_OK ], | ||||||||||||||
| 42 | ); | ||||||||||||||
| 43 | |||||||||||||||
| 44 | ################################################################# | ||||||||||||||
| 45 | |||||||||||||||
| 46 | # Have to do this the hard way instead of just calling | ||||||||||||||
| 47 | # PACKAGE($1)->abbreviate because of load-order issues. | ||||||||||||||
| 48 | 0 | ▶ | sub pkg_abbr($) { | ||||||||||||
|
Subroutine
pkg_abbr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 49 | 0 | ▶ | my $long_pack = shift; | ||||||||||||
|
Subroutine
pkg_abbr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 50 | 0 | require FindApp::Utils::Package::Object; | |||||||||||||
| 51 | 0 | FindApp::Utils::Package::Object->new($long_pack)->abbreviate(1); | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | sub class_prune(_) { | ||||||||||||
|
Subroutine
class_prune: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 55 | 0 | ▶ | my($string) = @_; | ||||||||||||
|
Subroutine
class_prune: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 56 | 0 | ▶ | return $string unless $FINDAPP_DEBUG_SHORTEN; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 57 | 0 | my @lines = split "\n", $string, -1; | |||||||||||||
| 58 | 0 | for (@lines) { | |||||||||||||
| 59 | 0 | s/\b(FindApp(?:::\w+)+)(?=::)/pkg_abbr($1)/ge; | |||||||||||||
| 60 | 0 | s/^ / /; | |||||||||||||
| 61 | 0 | s/^ / /; | |||||||||||||
| 62 | 0 | s/^ //; | |||||||||||||
| 63 | 0 | ▶ | s/ (?==)// || s/ (?==)//; # this may not be a good idea | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 64 | } | ||||||||||||||
| 65 | 0 | $string = join "\n", @lines; | |||||||||||||
| 66 | 0 | return $string; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | ▶ | sub as_string($) { | ||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 70 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 71 | 0 | my $pretty = pp($self) . ";\n"; | |||||||||||||
| 72 | 0 | $pretty = class_prune($pretty); | |||||||||||||
| 73 | 0 | my $string = sprintf "%s=%s(%#x)", map { (ref, reftype, refaddr) } $self; | |||||||||||||
| 74 | 0 | $pretty =~ s/.*\K/ # $string/; | |||||||||||||
| 75 | 0 | return $pretty; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 30 | ▶ | sub as_number($) { | ||||||||||||
|
Subroutine
as_number: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||
| 79 | 0 | ▶ | my($self) = @_; | ||||||||||||
|
Subroutine
as_number: not called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||
| 80 | 6 | ▶ | no overloading; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 81 | 0 | return refaddr($self); | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | ▶ | sub op_equals($$$) { | ||||||||||||
|
Subroutine
op_equals: not called CC=1 SCAR=1.7
Pod
documented
| |||||||||||||||
| 85 | 0 | ▶ | my($this, $that, $swapped) = @_; | ||||||||||||
|
Subroutine
op_equals: not called CC=1 SCAR=1.7
Pod
documented
| |||||||||||||||
| 86 | 6 | ▶ | no overloading; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 87 | 0 | return $this == $that; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 0 | ▶ | sub op_notequals($$$) { !&op_equals } | ||||||||||||
|
Subroutine
op_notequals: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 91 | |||||||||||||||
| 92 | |||||||||||||||
| 93 | # So that if you call an instance method on a class, you | ||||||||||||||
| 94 | # deliberately get the current singleton object instead. | ||||||||||||||
| 95 | 645 | ▶ | sub myself { | ||||||||||||
|
Subroutine
myself: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 96 | 645 | my $self = shift; | |||||||||||||
| 97 | 645 | ▶ | return $self if blessed $self; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 98 | 8 | return $self->old; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | |||||||||||||||
| 101 | 6 | 1; | |||||||||||||
| 102 | |||||||||||||||
| 103 | =encoding utf8 | ||||||||||||||
| 104 | |||||||||||||||
| 105 | =head1 NAME | ||||||||||||||
| 106 | |||||||||||||||
| 107 | FindApp::Utils::Objects - FIXME | ||||||||||||||
| 108 | |||||||||||||||
| 109 | =head1 SYNOPSIS | ||||||||||||||
| 110 | |||||||||||||||
| 111 | use FindApp::Utils::Objects; | ||||||||||||||
| 112 | |||||||||||||||
| 113 | =head1 DESCRIPTION | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =head2 Public Methods | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =over | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =item FIXME | ||||||||||||||
| 120 | |||||||||||||||
| 121 | =back | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =head2 Exports | ||||||||||||||
| 124 | |||||||||||||||
| 125 | =over | ||||||||||||||
| 126 | |||||||||||||||
| 127 | =item as_number | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =item as_string | ||||||||||||||
| 130 | |||||||||||||||
| 131 | =item class_prune | ||||||||||||||
| 132 | |||||||||||||||
| 133 | =item myself | ||||||||||||||
| 134 | |||||||||||||||
| 135 | Highly magical function that allows instance methods to act on a cached | ||||||||||||||
| 136 | class singleton when invoked as a class method not an instance | ||||||||||||||
| 137 | |||||||||||||||
| 138 | =item op_equals | ||||||||||||||
| 139 | |||||||||||||||
| 140 | =item op_notequals | ||||||||||||||
| 141 | |||||||||||||||
| 142 | =item pkg_abbr | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =back | ||||||||||||||
| 145 | |||||||||||||||
| 146 | =head1 EXAMPLES | ||||||||||||||
| 147 | |||||||||||||||
| 148 | =head1 ENVIRONMENT | ||||||||||||||
| 149 | |||||||||||||||
| 150 | =head1 SEE ALSO | ||||||||||||||
| 151 | |||||||||||||||
| 152 | =over | ||||||||||||||
| 153 | |||||||||||||||
| 154 | =item L<FindApp> | ||||||||||||||
| 155 | |||||||||||||||
| 156 | =back | ||||||||||||||
| 157 | |||||||||||||||
| 158 | =head1 CAVEATS AND PROVISOS | ||||||||||||||
| 159 | |||||||||||||||
| 160 | =head1 BUGS AND LIMITATIONS | ||||||||||||||
| 161 | |||||||||||||||
| 162 | =head1 HISTORY | ||||||||||||||
| 163 | |||||||||||||||
| 164 | =head1 AUTHOR | ||||||||||||||
| 165 | |||||||||||||||
| 166 | Tom Christiansen << <tchrist@perl.com> >> | ||||||||||||||
| 167 | |||||||||||||||
| 168 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||
| 169 | |||||||||||||||
| 170 | Copyright (c) 2016, Tom Christiansen C<< <tchrist@perl.com> >>. | ||||||||||||||
| 171 | All Rights Reserved. | ||||||||||||||
| 172 | |||||||||||||||
| 173 | This module is free software; you can redistribute it and/or | ||||||||||||||
| 174 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||||||
| 175 | |||||||||||||||
| 176 | =cut | ||||||||||||||
| 177 | |||||||||||||||