Skip to content

Commit

Permalink
[#290 state:resolved] [#351 state:resolved] Refactored `MT::App::para…
Browse files Browse the repository at this point in the history
…m()`. See full commit for bulleted highlights.

* Refactored `MT::App::param()` to eliminate tangled logic introduced by bugs in `MT::App::query` (see previous commit) bugs that caused it to not report
* Created package `Melody::DeprecatedParamUsage` inside `MT::App` to hold the messy warning code in `MT::App::param()`. This leaves the method looking almost like it does in MT which helps ensure that we aren't introducing bugs in the backwards compatibility of the method.
    * Like `Melody::DeprecatedQueryUsage`, `Melody::DeprecatedParamUsage` really needs to be moved to an official compat module for Melody deprecations and backward-compatibility because we're going to have a lot of them in the future.
* Fixed bug #351 in which backwards-compatibility of `$app->param` was broken when called in a list context with no arguments (i.e. `my %param = $app->param;`). Was returning `$app->query->param` which is an array of param keys
* Better deprecation warnings telling the developer exact what kind of access triggered the deprecation warning and the recommended way to update their code.
  • Loading branch information
jayallen committed Jul 27, 2010
1 parent 9aeaaaf commit 57fe074
Showing 1 changed file with 55 additions and 16 deletions.
71 changes: 55 additions & 16 deletions lib/MT/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3297,6 +3297,9 @@ sub delete_param {
}
}

######## DEPRECATED AND FUTURE BREAK ##########
# Please see this method's POD documentation #
###############################################
sub param_hash {
my $app = shift;
my $q = $app->query;
Expand Down Expand Up @@ -3539,27 +3542,25 @@ sub redirect {
return;
}

# FUTURE BREAK & DEPRECATED. Emit warning unless it's the new query
# method calling.
######## DEPRECATED AND FUTURE BREAK ##########
# Please see this method's POD documentation #
###############################################
sub param {
my $app = shift;
my ($package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask
) = caller(1);
unless ($subroutine && $subroutine eq 'MT::App::query') {
warn <<MSG;
FUTURE BREAK WARNING: Deprecated usage of MT::App->param to fetch
the CGI query object in $package at line $line.
This will be changed in a backwards incompatable way in the near
future. Use MT::App->query instead.
MSG
}
return unless $app->query;
my $q = $app->query or return; # Hapless if not harmless...
if (@_) {
$app->query->param(@_);
Melody::DeprecatedParamUsage->warn( $app, 'get_set' );
return $q->param(@_);
}
else {
wantarray ? ($app->query->param) : $app->query;
if ( wantarray ) {
Melody::DeprecatedParamUsage->warn( $app, 'param_hash' );
return ( map { $_ => $q->param($_) } $q->param );
}
else {
Melody::DeprecatedParamUsage->warn( $app, 'query_object' );
return $q;
}
}
}

Expand Down Expand Up @@ -3746,6 +3747,44 @@ sub set_no_cache {
}
}




package Melody::DeprecatedParamUsage;

# FIXME Move Melody::DeprecatedParamUsage to a Melody compatibility layer

sub warn {
my $self = shift;
my ( $app, $type ) = @_;
my ( $package, $filename, $line ) = caller(1);
my $msg = 'DEPRECATION WARNING: Use of $app->param to [_1] in [_2] '
. 'at line [_3] will break in the future. Use [_4] instead.';

# Mapping of each type of deprecated $app->param usage
# to an expanded description and replacement method
my %usage = (
get_set => {
description => 'get/set query object properties',
replacement => '$app->query->param()',
},
param_hash => {
description => 'fetch a hash of query parameters',
replacement => '$app->query->param',
},
query_object => {
description => 'fetch the CGI query object',
replacement => '$app->query',
},
);
my $transmsg = $app->translate(
$msg, $usage{$type}{description}, $package,
$line, $usage{$type}{replacement}
);
print STDERR $transmsg."\n";
warn $transmsg."\n";
}

package Melody::DeprecatedQueryUsage;

# FIXME Move Melody::DeprecatedQueryUsage to a Melody compatibility layer
Expand Down

0 comments on commit 57fe074

Please sign in to comment.