This file is indexed.

/usr/share/perl5/Mock/Quick/Util.pm is in libmock-quick-perl 1.108-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package Mock::Quick::Util;
use strict;
use warnings;

use base 'Exporter';
use Scalar::Util qw/blessed/;
use Mock::Quick::Method;
use Carp qw/croak/;

our $CLEAR = 'clear';
our @EXPORT = qw/
    class_meth
    obj_meth
    alt_meth
    call
    param
    inject
    purge_util
    super
/;

sub inject {
    my ( $package, $name, $code ) = @_;
    no warnings 'redefine';
    no strict 'refs';
    *{"$package\::$name"} = $code;
}

sub call {
    my $self = shift;
    require Mock::Quick::Object::Control;
    my $control = Mock::Quick::Object::Control->new( $self );
    my $name = shift;

    my $class = blessed( $self );
    croak "Can't call method on an unblessed reference"
        unless $class;

    if ( $control->strict ) {
        croak "Can't locate object method \"$name\" in this instance"
            unless exists $self->{$name};
    }

    if ( @_ && ref $_[0] && $_[0] == \$CLEAR ) {
        delete $self->{ $name };
        delete $control->metrics->{$name};
        return;
    }

    $control->metrics->{$name}++;

    return $self->{ $name }->( $self, @_ )
        if exists(  $self->{ $name })
        && blessed( $self->{ $name })
        && blessed( $self->{ $name })->isa( 'Mock::Quick::Method' );

    return $self->{$name} = shift(@_)
        if blessed( $_[0] ) && blessed( $_[0] )->isa( 'Mock::Quick::Method' );

    param( $self, $name, @_ );
}

sub param {
    my $self = shift;
    my $name = shift;

    $self->{$name} = shift(@_) if @_;

    # Prevent autovivication
    return unless exists( $self->{ $name });
    return $self->{ $name };
}

sub class_meth {
    my ( $name, $block ) = @_;
    my $caller = caller;

    my $sub = sub {
        goto &$block unless blessed( $_[0] );
        unshift @_ => ( shift(@_), $name );
        goto &call;
    };

    inject( $caller, $name, $sub );
}

sub obj_meth {
    my ( $name, $block ) = @_;
    my $caller = caller;

    my $sub = sub {
        goto &$block if blessed( $_[0] );
        Carp::croak( "Can't locate object method \"$name\" via package \"$caller\"" );
    };

    inject( $caller, $name, $sub );
}

sub alt_meth {
    my ( $name, %alts ) = @_;
    my $caller = caller;

    croak "You must provide an action for both 'class' and 'obj'"
        unless $alts{class} && $alts{obj};

    my $sub = sub {
        goto &{ $alts{obj }} if blessed( $_[0] );
        goto &{ $alts{ class }};
    };

    inject( $caller, $name, $sub );
}

sub purge_util {
    my $caller = caller;
    for my $sub ( @EXPORT ) {
        no strict 'refs';
        my $ref = \%{"$caller\::"};
        delete $ref->{ $sub };
    }
}

1;

__END__

=head1 NAME

Mock::Quick::Util - Uitls for L<Mock::Quick>.

=head1 AUTHORS

Chad Granum L<exodist7@gmail.com>

=head1 COPYRIGHT

Copyright (C) 2011 Chad Granum

Mock-Quick is free software; Standard perl licence.

Mock-Quick is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the license for more details.