Skip to content

Commit

Permalink
Rename warn_deprecated to deprecated, reformat missing transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusramberg committed Feb 23, 2013
1 parent 1bee554 commit 0dab946
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/Home.pm
Expand Up @@ -10,7 +10,7 @@ use File::Basename 'dirname';
use File::Find 'find';
use File::Spec::Functions qw(abs2rel catdir catfile splitdir);
use FindBin;
use Mojo::Util qw(class_to_path slurp warn_deprecated);
use Mojo::Util qw(class_to_path slurp deprecated);

sub new { shift->SUPER::new->parse(@_) }

Expand Down Expand Up @@ -82,7 +82,7 @@ sub rel_file { catfile(@{shift->{parts} || []}, split '/', shift) }

# DEPRECATED in Rainbow!
sub slurp_rel_file {
warn_deprecated
deprecated
"Mojo::Home->slurp_rel_file is DEPRECATED in favor of Mojo::Util->slurp!!!";
slurp shift->rel_file(@_);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -8,7 +8,7 @@ use List::Util 'first';
use Mojo::IOLoop;
use Mojo::Server::Daemon;
use Mojo::URL;
use Mojo::Util qw(monkey_patch warn_deprecated);
use Mojo::Util qw(monkey_patch deprecated);
use Mojo::UserAgent::CookieJar;
use Mojo::UserAgent::Transactor;
use Scalar::Util 'weaken';
Expand Down Expand Up @@ -61,14 +61,14 @@ sub app_url {

# DEPRECATED in Rainbow!
sub build_form_tx {
warn_deprecated "Mojo::UserAgent->build_form_tx is DEPRECATED "
deprecated "Mojo::UserAgent->build_form_tx is DEPRECATED "
. "in favor of Mojo::UserAgent->build_tx!!!";
shift->transactor->form(@_);
}

# DEPRECATED in Rainbow!
sub build_json_tx {
warn_deprecated "Mojo::UserAgent->build_json_tx is DEPRECATED "
deprecated "Mojo::UserAgent->build_json_tx is DEPRECATED "
. "in favor of Mojo::UserAgent->build_tx!!!";
shift->transactor->json(@_);
}
Expand All @@ -90,7 +90,7 @@ sub need_proxy {

# DEPRECATED in Rainbow!
sub post_form {
warn_deprecated
deprecated
"Mojo::UserAgent->post_form is DEPRECATED in favor of Mojo::UserAgent->post!!!";
my $self = shift;
my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -11,7 +11,7 @@ use Mojo::Parameters;
use Mojo::Transaction::HTTP;
use Mojo::Transaction::WebSocket;
use Mojo::URL;
use Mojo::Util qw(encode warn_deprecated);
use Mojo::Util qw(encode deprecated);

has generators => sub { {} };

Expand Down Expand Up @@ -47,8 +47,8 @@ sub endpoint {

# DEPRECATED in Rainbow!
sub form {
warn_deprecated
"Mojo::UserAgent::Transactor->form is DEPRECATED in favor of Mojo::UserAgent::Transactor->tx!!!";
deprecated "Mojo::UserAgent::Transactor->form is DEPRECATED "
. "in favor of Mojo::UserAgent::Transactor->tx!!!";
my ($self, $url, $charset) = (shift, shift, shift);
my $form = ref $charset ? $charset : shift;
$charset = undef if ref $charset;
Expand All @@ -57,8 +57,8 @@ sub form {

# DEPRECATED in Rainbow!
sub json {
warn_deprecated
"Mojo::UserAgent::Transactor->json is DEPRECATED in favor of Mojo::UserAgent::Transactor->tx!!!";
deprecated "Mojo::UserAgent::Transactor->json is DEPRECATED "
. "in favor of Mojo::UserAgent::Transactor->tx!!!";
my ($self, $url, $data) = (shift, shift, shift);
return $self->tx(POST => $url, @_, json => $data);
}
Expand Down
22 changes: 11 additions & 11 deletions lib/Mojo/Util.pm
Expand Up @@ -45,7 +45,7 @@ our @EXPORT_OK = (
qw(decode encode get_line hmac_md5_sum hmac_sha1_sum html_unescape),
qw(md5_bytes md5_sum monkey_patch punycode_decode punycode_encode quote),
qw(secure_compare sha1_bytes sha1_sum slurp spurt squish trim unquote),
qw(url_escape url_unescape warn_deprecated xml_escape xor_encode)
qw(url_escape url_unescape deprecated xml_escape xor_encode)
);

# DEPRECATED in Rainbow!
Expand Down Expand Up @@ -98,6 +98,12 @@ sub decode {
return $bytes;
}
sub deprecated {
my $deprecation = shift;
local $Carp::CarpLevel = 1;
$ENV{MOJO_FATAL_DEPRECATIONS} ? croak($deprecation) : carp($deprecation);
}
sub encode { _encoding($_[0])->encode("$_[1]") }
sub get_line {
Expand Down Expand Up @@ -394,12 +400,6 @@ sub _hmac {
return unpack 'H*', $hash->($opad . $hash->($ipad . $string));
}

sub warn_deprecated {
my $deprecation = shift;
local $Carp::CarpLevel = 1;
$ENV{MOJO_FATAL_DEPRECATIONS} ? croak($deprecation) : carp($deprecation);
}

1;

=head1 NAME
Expand Down Expand Up @@ -492,6 +492,10 @@ Convert camel case string to snake case and replace C<::> with C<->.
Decode bytes to characters and return C<undef> if decoding failed.
=head2 deprecated
deprecated "Mojo::foo DEPRECATED in favor of Mojo::bar";
=head2 encode
my $bytes = encode 'UTF-8', $chars;
Expand Down Expand Up @@ -628,10 +632,6 @@ C<^A-Za-z0-9\-._~>.
Decode percent encoded characters in string.
=head2 warn_deprecated
warn_deprecated "Mojo::foo DEPRECATED in favor of Mojo::bar";
Warn about deprecated feature from perspective of caller. Set environment
variable MOJO_FATAL_DEPRECATIONS to make deprecations fatal.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base 'Mojo';
# "Fry: Shut up and take my money!"
use Carp 'croak';
use Mojo::Exception;
use Mojo::Util qw(decamelize warn_deprecated);
use Mojo::Util qw(decamelize deprecated);
use Mojolicious::Commands;
use Mojolicious::Controller;
use Mojolicious::Plugins;
Expand Down Expand Up @@ -122,7 +122,7 @@ sub dispatch {

# DEPRECATED in Rainbow!
if ($plugins->has_subscribers('after_static_dispatch')) {
warn_deprecated "after_static_dispatch hook is DEPRECATED "
deprecated "after_static_dispatch hook is DEPRECATED "
. "in favor of before_routes!!!"
and $plugins->emit_hook_reverse(after_static_dispatch => $c);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Commands.pm
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base 'Mojolicious::Command';
use Getopt::Long 'GetOptions';
use List::Util 'max';
use Mojo::Server;
use Mojo::Util 'warn_deprecated';
use Mojo::Util 'deprecated';

has hint => <<"EOF";
Expand Down Expand Up @@ -106,7 +106,7 @@ sub run {

# DEPRECATED in Rainbow!
sub start {
warn_deprecated "Mojolicious::Commands->start is DEPRECATED "
deprecated "Mojolicious::Commands->start is DEPRECATED "
. "in favor of Mojolicious::Commands->start_app!!!";
my $self = shift;
return $self->start_app($ENV{MOJO_APP} => @_) if $ENV{MOJO_APP};
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base 'Mojolicious::Plugin';

use Data::Dumper ();
use Mojo::ByteStream;
use Mojo::Util 'warn_deprecated';
use Mojo::Util 'deprecated';

sub register {
my ($self, $app) = @_;
Expand Down Expand Up @@ -61,7 +61,7 @@ sub register {
# DEPRECATED in Rainbow!
$app->helper(
render_content => sub {
warn_deprecated "Mojolicious::Controller->render_content is DEPRECATED!";
deprecated "Mojolicious::Controller->render_content is DEPRECATED!";
shift->content(@_);
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -2,7 +2,7 @@ package Mojolicious::Plugin::TagHelpers;
use Mojo::Base 'Mojolicious::Plugin';

use Mojo::ByteStream 'b';
use Mojo::Util qw(xml_escape warn_deprecated);
use Mojo::Util qw(xml_escape deprecated);

sub register {
my ($self, $app) = @_;
Expand All @@ -16,7 +16,7 @@ sub register {
# DEPRECATED in Rainbow!
$app->helper(
base_tag => sub {
warn_deprecated "base_tag is DEPRECATED!!!";
deprecated "base_tag is DEPRECATED!!!";
_tag('base', href => shift->req->url->base, @_);
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Routes.pm
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base 'Mojolicious::Routes::Route';
use List::Util 'first';
use Mojo::Cache;
use Mojo::Loader;
use Mojo::Util qw(camelize warn_deprecated);
use Mojo::Util qw(camelize deprecated);
use Mojolicious::Routes::Match;
use Scalar::Util 'weaken';

Expand Down Expand Up @@ -81,7 +81,7 @@ sub lookup {

# DEPRECATED in Rainbow!
sub namespace {
warn_deprecated "Mojolicious::Routes->namespace is DEPRECATED "
deprecated "Mojolicious::Routes->namespace is DEPRECATED "
. "in favor of Mojolicious::Routes->namespaces!";
my $self = shift;
return $self->namespaces->[0] unless @_;
Expand Down
8 changes: 4 additions & 4 deletions lib/Test/Mojo.pm
Expand Up @@ -13,7 +13,7 @@ use Mojo::JSON;
use Mojo::JSON::Pointer;
use Mojo::Server;
use Mojo::UserAgent;
use Mojo::Util qw(decode encode warn_deprecated);
use Mojo::Util qw(decode encode deprecated);
use Test::More ();

has [qw(message tx)];
Expand Down Expand Up @@ -220,7 +220,7 @@ sub post_ok { shift->_request_ok(post => @_) }

# DEPRECATED in Rainbow!
sub post_form_ok {
warn_deprecated "Test::Mojo->post_form_ok is DEPRECATED "
deprecated "Test::Mojo->post_form_ok is DEPRECATED "
. "in favor of Test::Mojo->post_ok!!!";
my ($self, $url) = (shift, shift);
my $tx = $self->tx($self->ua->post_form($url, @_))->tx;
Expand All @@ -229,7 +229,7 @@ sub post_form_ok {

# DEPRECATED in Rainbow!
sub post_json_ok {
warn_deprecated "Test::Mojo->post_json_ok is DEPRECATED "
deprecated "Test::Mojo->post_json_ok is DEPRECATED "
. "in favor of Test::Mojo->post_ok!!!";
my ($self, $url) = (shift, shift);
my $tx = $self->tx($self->ua->post_json($url, @_))->tx;
Expand Down Expand Up @@ -375,7 +375,7 @@ sub _wait {

# DEPRECATED in Rainbow!
my $new = $self->{new} //= $wait;
warn_deprecated "Testing WebSocket messages without "
deprecated "Testing WebSocket messages without "
. "Test::Mojo->message_ok is DEPRECATED!!!"
unless $new;
return $self->message if $new && !$wait;
Expand Down
6 changes: 3 additions & 3 deletions lib/ojo.pm
Expand Up @@ -6,7 +6,7 @@ use Mojo::Collection 'c';
use Mojo::DOM;
use Mojo::JSON 'j';
use Mojo::UserAgent;
use Mojo::Util qw(monkey_patch warn_deprecated);
use Mojo::Util qw(monkey_patch deprecated);

# Silent oneliners
$ENV{MOJO_LOG_LEVEL} ||= 'fatal';
Expand Down Expand Up @@ -42,11 +42,11 @@ sub import {

# DEPRECATED in Rainbow!
my $f = sub {
warn_deprecated "ojo->f is DEPRECATED in favor of ojo->p!!!";
deprecated "ojo->f is DEPRECATED in favor of ojo->p!!!";
_request($UA->build_form_tx(@_));
};
my $n = sub {
warn_deprecated "ojo->n is DEPRECATED in favor of ojo->p!!!";
deprecated "ojo->n is DEPRECATED in favor of ojo->p!!!";
_request($UA->build_json_tx(@_));
};
monkey_patch $caller, f => $f, n => $n;
Expand Down
12 changes: 6 additions & 6 deletions t/mojo/util.t
Expand Up @@ -7,10 +7,10 @@ use FindBin;

use Mojo::Util
qw(b64_decode b64_encode camelize class_to_file class_to_path decamelize),
qw(decode encode get_line hmac_md5_sum hmac_sha1_sum html_unescape),
qw(md5_bytes md5_sum monkey_patch punycode_decode punycode_encode quote),
qw(decode deprecated encode get_line hmac_md5_sum hmac_sha1_sum),
qw(html_unescape md5_bytes md5_sum monkey_patch punycode_decode),
qw(squish trim unquote secure_compare sha1_bytes sha1_sum slurp spurt),
qw(url_escape url_unescape warn_deprecated xml_escape xor_encode);
qw(punycode_encode quote url_escape url_unescape xml_escape xor_encode);

# camelize
is camelize('foo_bar_baz'), 'FooBarBaz', 'right camelized result';
Expand Down Expand Up @@ -400,15 +400,15 @@ is MojoMonkeyTest::yin(), 'yin', 'right result';
ok !!MojoMonkeyTest->can('yang'), 'function "yang" exists';
is MojoMonkeyTest::yang(), 'yang', 'right result';

# warn_deprecated
# deprecated

{
my ($warn, $die) = @_;
local $SIG{__WARN__} = sub { $warn = shift; };
local $SIG{__DIE__} = sub { $die = shift; return undef; };
warn_deprecated("This warns from caller");
deprecated("This warns from caller");
local $ENV{MOJO_FATAL_DEPRECATIONS} = 1;
eval { warn_deprecated("This dies from caller"); };
eval { deprecated("This dies from caller"); };
like(
$warn,
qr/This warns from caller at t\/mojo\/util.t line \d+/,
Expand Down

0 comments on commit 0dab946

Please sign in to comment.