[Rt-commit] rt branch, 4.2/deprecated-method, created. rt-4.1.5-209-g69a612f

Alex Vandiver alexmv at bestpractical.com
Mon Dec 31 16:24:12 EST 2012


The branch, 4.2/deprecated-method has been created
        at  69a612fac61cc5800761a59ed8f379697b01be83 (commit)

- Log -----------------------------------------------------------------
commit fbcee08893b9882ccab88f3fd33c689f58095592
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Dec 31 16:23:02 2012 -0500

    Add an RT->Deprecated method to have a standard manner of deprecating calls

diff --git a/lib/RT.pm b/lib/RT.pm
index fd4415d..b92fdf0 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -803,6 +803,73 @@ sub StyleSheets {
     return RT->Config->Get('CSSFiles');
 }
 
+=head2 Deprecated
+
+Notes that a particular call path is deprecated, and will be removed in
+a particular release.  Puts a warning in the logs indicating such, along
+with a stack trace.
+
+Optional arguments include:
+
+=over
+
+=item Remove
+
+The release which is slated to remove the method or component
+
+=item Instead
+
+A suggestion of what to use in place of the deprecated API
+
+=item Arguments
+
+Used if not the entire method is being removed, merely a manner of
+calling it; names the arguments which are deprecated.
+
+=back
+
+=cut
+
+sub Deprecated {
+    my $class = shift;
+    my %args = (
+        Arguments => undef,
+        Remove => undef,
+        Instead => undef,
+        @_,
+    );
+
+    my ($function) = (caller(1))[3];
+    my $stack;
+    if ($function eq "HTML::Mason::Commands::__ANON__") {
+        eval { HTML::Mason::Exception->throw() };
+        my $error = $@;
+        my $info = $error->analyze_error;
+        $function = "Mason component ".$info->{frames}[0]->filename;
+        $stack = join("\n", map { sprintf("\t[%s:%d]", $_->filename, $_->line) } @{$info->{frames}});
+    } else {
+        $function = "function $function";
+        $stack = Carp::longmess();
+    }
+    $stack =~ s/^.*?\n//; # Strip off call to ->Deprecated
+
+    my $msg;
+    if ($args{Arguments}) {
+        $msg = "Calling $function with $args{Arguments} is deprecated";
+    } else {
+        $msg = "The $function is deprecated";
+    }
+    $msg .= ", and will be removed in RT $args{Remove}"
+        if $args{Remove};
+    $msg .= ".";
+
+    $msg .= "  You should use $args{Instead} instead."
+        if $args{Instead};
+
+    $msg .= "  Call stack:\n$stack";
+    RT->Logger->warn($msg);
+}
+
 =head1 BUGS
 
 Please report them to rt-bugs at bestpractical.com, if you know what's

commit 69a612fac61cc5800761a59ed8f379697b01be83
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Dec 31 16:24:07 2012 -0500

    Update deprecated callsite to use new RT->Deprecated call

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 30c08db..ec40354 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -749,7 +749,11 @@ sub ValidateType {
     my $type = shift;
 
     if ( $type =~ s/(?:Single|Multiple)$// ) {
-        $RT::Logger->warning( "Prefix 'Single' and 'Multiple' to Type deprecated, use MaxValues instead at (". join(":",caller).")");
+        RT->Deprecated(
+            Arguments => "prefix 'Single' or 'Multiple'",
+            Instead   => "MaxValues",
+            Remove    => "4.4",
+        );
     }
 
     if ( $FieldTypes{$type} ) {
@@ -765,7 +769,11 @@ sub SetType {
     my $self = shift;
     my $type = shift;
     if ($type =~ s/(?:(Single)|Multiple)$//) {
-        $RT::Logger->warning("'Single' and 'Multiple' on SetType deprecated, use SetMaxValues instead at (". join(":",caller).")");
+        RT->Deprecated(
+            Arguments => "prefix 'Single' or 'Multiple'",
+            Instead   => "MaxValues",
+            Remove    => "4.4",
+        );
         $self->SetMaxValues($1 ? 1 : 0);
     }
     $self->_Set(Field => 'Type', Value =>$type);
@@ -1351,7 +1359,13 @@ sub IsOnlyGlobal {
     return ($self->LookupType =~ /^RT::(?:Group|User)/io);
 
 }
-sub ApplyGlobally { Carp::carp("DEPRECATED, use IsOnlyGlobal"); return shift->IsOnlyGlobal(@_) }
+sub ApplyGlobally {
+    RT->Deprecated(
+        Instead   => "IsOnlyGlobal",
+        Remove    => "4.4",
+    );
+    return shift->IsOnlyGlobal(@_);
+}
 
 =head1 AddedTo
 
@@ -1368,7 +1382,13 @@ sub AddedTo {
     return RT::ObjectCustomField->new( $self->CurrentUser )
         ->AddedTo( CustomField => $self );
 }
-sub AppliedTo { Carp::carp("DEPRECATED: use AddedTo"); shift->AddedTo(@_) };
+sub AppliedTo {
+    RT->Deprecated(
+        Instead   => "AddedTo",
+        Remove    => "4.4",
+    );
+    shift->AddedTo(@_);
+};
 
 =head1 NotAddedTo
 
@@ -1385,7 +1405,13 @@ sub NotAddedTo {
     return RT::ObjectCustomField->new( $self->CurrentUser )
         ->NotAddedTo( CustomField => $self );
 }
-sub NotAppliedTo { Carp::carp("DEPRECATED: use NotAddedTo"); shift->NotAddedTo(@_) };
+sub NotAppliedTo {
+    RT->Deprecated(
+        Instead   => "NotAddedTo",
+        Remove    => "4.4",
+    );
+    shift->NotAddedTo(@_)
+};
 
 =head2 IsAdded
 
@@ -1403,7 +1429,13 @@ sub IsAdded {
     return undef unless $ocf->id;
     return $ocf;
 }
-sub IsApplied { Carp::carp("DEPRECATED: use IsAdded"); shift->IsAdded(@_) };
+sub IsApplied {
+    RT->Deprecated(
+        Instead   => "IsAdded",
+        Remove    => "4.4",
+    );
+    shift->IsAdded(@_);
+};
 
 sub IsGlobal { return shift->IsAdded(0) }
 
diff --git a/lib/RT/Group.pm b/lib/RT/Group.pm
index 334314b..28e9081 100644
--- a/lib/RT/Group.pm
+++ b/lib/RT/Group.pm
@@ -350,11 +350,10 @@ sub LoadTicketRoleGroup {
         Type => undef,
         @_,
     );
-    RT->Logger->warn(<<"    .");
-RT::Group->LoadTicketRoleGroup is DEPRECATED and will be removed in a future release.
-
-Please use RT::Group->LoadRoleGroup or RT::Ticket->RoleGroup instead at @{[join '/', caller]}.
-    .
+    RT->Deprecated(
+        Instead => "RT::Group->LoadRoleGroup or RT::Ticket->RoleGroup",
+        Remove => "4.4",
+    );
     $self->LoadByCols(
         Domain   => 'RT::Ticket-Role',
         Instance => $args{'Ticket'},
@@ -377,11 +376,10 @@ sub LoadQueueRoleGroup {
         Type => undef,
         @_,
     );
-    RT->Logger->warn(<<"    .");
-RT::Group->LoadQueueRoleGroup is DEPRECATED and will be removed in a future release.
-
-Please use RT::Group->LoadRoleGroup or RT::Queue->RoleGroup instead at @{[join '/', caller]}.
-    .
+    RT->Deprecated(
+        Instead => "RT::Group->LoadRoleGroup or RT::Queue->RoleGroup",
+        Remove => "4.4",
+    );
     $self->LoadByCols(
         Domain   => 'RT::Queue-Role',
         Instance => $args{'Queue'},
@@ -400,11 +398,10 @@ Deprecated in favor of L</LoadRoleGroup> or L<RT::Record/RoleGroup>.
 sub LoadSystemRoleGroup {
     my $self = shift;
     my $type = shift;
-    RT->Logger->warn(<<"    .");
-RT::Group->LoadSystemRoleGroup is DEPRECATED and will be removed in a future release.
-
-Please use RT::Group->LoadRoleGroup or RT::System->RoleGroup instead at @{[join '/', caller]}.
-    .
+    RT->Deprecated(
+        Instead => "RT::Group->LoadRoleGroup or RT::System->RoleGroup",
+        Remove => "4.4",
+    );
     $self->LoadByCols(
         Domain => 'RT::System-Role',
         Type => $type
diff --git a/lib/RT/Groups.pm b/lib/RT/Groups.pm
index 0e3cc98..4c285b2 100644
--- a/lib/RT/Groups.pm
+++ b/lib/RT/Groups.pm
@@ -197,7 +197,10 @@ Limits the set of groups found to role groups for queue QUEUE_ID
 sub LimitToRolesForQueue {
     my $self = shift;
     my $queue = shift;
-    RT->Logger->warning("LimitToRolesForQueue is deprecated; please change code to use LimitToRolesForObject (caller @{[join '/', caller]})");
+    RT->Deprecated(
+        Instead => "LimitToRolesForObject",
+        Remove => "4.4",
+    );
     $self->Limit(FIELD => 'Domain', OPERATOR => '=', VALUE => 'RT::Queue-Role');
     $self->Limit(FIELD => 'Instance', OPERATOR => '=', VALUE => $queue);
 }
@@ -215,7 +218,10 @@ Limits the set of groups found to role groups for Ticket Ticket_ID
 sub LimitToRolesForTicket {
     my $self = shift;
     my $Ticket = shift;
-    RT->Logger->warning("LimitToRolesForTicket is deprecated; please change code to use LimitToRolesForObject (caller @{[join '/', caller]})");
+    RT->Deprecated(
+        Instead => "LimitToRolesForObject",
+        Remove => "4.4",
+    );
     $self->Limit(FIELD => 'Domain', OPERATOR => '=', VALUE => 'RT::Ticket-Role');
     $self->Limit(FIELD => 'Instance', OPERATOR => '=', VALUE => $Ticket);
 }
@@ -232,7 +238,10 @@ Limits the set of groups found to role groups for System System_ID
 
 sub LimitToRolesForSystem {
     my $self = shift;
-    RT->Logger->warning("LimitToRolesForSystem is deprecated; please change code to use LimitToRolesForObject (caller @{[join '/', caller]})");
+    RT->Deprecated(
+        Instead => "LimitToRolesForObject",
+        Remove => "4.4",
+    );
     $self->Limit(FIELD => 'Domain', OPERATOR => '=', VALUE => 'RT::System-Role');
 }
 
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 8f2f46b..c8f0e2e 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -160,7 +160,10 @@ sub EscapeHTML {
 # Back-compat
 # XXX: Remove in 4.4
 sub EscapeUTF8 {
-    RT->Logger->warning("EscapeUTF8 is deprecated; use EscapeHTML at @{[join '/', caller]}");
+    RT->Deprecated(
+        Instead => "EscapeHTML",
+        Remove => "4.4",
+    );
     EscapeHTML(@_);
 }
 
diff --git a/lib/RT/Interface/Web/Request.pm b/lib/RT/Interface/Web/Request.pm
index d38b2fd..f0b3939 100644
--- a/lib/RT/Interface/Web/Request.pm
+++ b/lib/RT/Interface/Web/Request.pm
@@ -65,8 +65,6 @@ sub new {
 
 =head2 callback
 
-Method replaces deprecated component C<Element/Callback>.
-
 Takes hash with optional C<CallbackPage>, C<CallbackName>
 and C<CallbackOnce> arguments, other arguments are passed
 throught to callback components.
diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index b161411..98c91d7 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -731,11 +731,10 @@ them, see L</ManageableRoleGroupTypes>.
 =cut
 
 sub AllRoleGroupTypes {
-    RT->Logger->warn(<<"    .");
-RT::Queue->AllRoleGroupTypes is DEPRECATED and will be removed in a future release.
-
-Please use RT::Queue->Roles instead at @{[join '/', caller]}.
-    .
+    RT->Deprecated(
+        Remove => "4.4",
+        Instead => "RT::Queue->Roles",
+    );
     shift->Roles;
 }
 
@@ -748,11 +747,10 @@ Returns whether the passed-in type is a role group type.
 =cut
 
 sub IsRoleGroupType {
-    RT->Logger->warn(<<"    .");
-RT::Queue->IsRoleGroupType is DEPRECATED and will be removed in a future release.
-
-Please use RT::Queue->HasRole instead at @{[join '/', caller]}.
-    .
+    RT->Deprecated(
+        Remove => "4.4",
+        Instead => "RT::Queue->HasRole",
+    );
     shift->HasRole(@_);
 }
 
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index ee5a8bc..c0e7789 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -156,6 +156,10 @@ DEPRECATED. Stays here for backwards. Returns localized L</RecordType>.
 
 sub ObjectTypeStr {
     my $self = shift;
+    RT->Deprecated(
+        Remove => "4.4",
+        Instead => "RecordType",
+    );
     return $self->loc( $self->RecordType( @_ ) );
 }
 
@@ -436,15 +440,20 @@ sub CreatedObj {
 # B<DEPRECATED> and will be removed in 4.4
 sub AgeAsString {
     my $self = shift;
-    $RT::Logger->warning("RT::Record->AgeAsString is deprecated and will be removed in RT 4.4; use ->CreatedObj->AgeAsString instead");
+    RT->Deprecated(
+        Remove => "4.4",
+        Instead => "->CreatedObj->AgeAsString",
+    );
     return ( $self->CreatedObj->AgeAsString() );
 }
 
 # B<DEPRECATED> and will be removed in 4.4
 sub LongSinceUpdateAsString {
     my $self = shift;
-    $RT::Logger->warning("RT::Record->LongSinceUpdateAsString is deprecated and will be removed in RT 4.4; use ->LastUpdatedObj->AgeAsString instead");
-
+    RT->Deprecated(
+        Remove => "4.4",
+        Instead => "->LastUpdatedObj->AgeAsString",
+    );
     if ( $self->LastUpdated ) {
         return ( $self->LastUpdatedObj->AgeAsString() );
     } else {
diff --git a/lib/RT/ScripAction.pm b/lib/RT/ScripAction.pm
index a8d68a9..6a4781f 100644
--- a/lib/RT/ScripAction.pm
+++ b/lib/RT/ScripAction.pm
@@ -131,7 +131,10 @@ sub Load  {
     }
 
     if (@_) {
-        $RT::Logger->warning("Passing in Template as second argument is deprecated");
+        RT->Deprecated(
+            Arguments => "Template as second argument",
+            Remove    => "4.4",
+        );
         $self->{'Template'} = shift;
     }
 
@@ -180,13 +183,15 @@ sub LoadAction  {
 
 =head2 TemplateObj
 
-Return this action's template object
+Return this action's template object.  Deprecated.
 
 =cut
 
 sub TemplateObj {
     my $self = shift;
-    Carp::carp(__PACKAGE__."::TemplateObj is deprecated");
+    RT->Deprecated(
+        Remove => "4.4",
+    );
 
     return undef unless $self->{Template};
     if ( !$self->{'TemplateObj'} ) {
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 4d20523..0bddab1 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -1504,7 +1504,10 @@ $ticket->DueObj->AsString >> instead.
 
 sub DueAsString {
     my $self = shift;
-    $RT::Logger->warning("RT::Ticket->DueAsString is deprecated and will be removed in RT 4.4; use ->DueObj->AsString instead");
+    RT->Deprecated(
+        Instead => "->DueObj->AsString",
+        Remove => "4.4",
+    );
     return $self->DueObj->AsString();
 }
 
@@ -1690,7 +1693,10 @@ $ticket->ToldObj->AsString >> instead.
 
 sub ToldAsString {
     my $self = shift;
-    $RT::Logger->warning("RT::Ticket->ToldAsString is deprecated and will be removed in RT 4.4; use ->ToldObj->AsString instead");
+    RT->Deprecated(
+        Instead => "->ToldObj->AsString",
+        Remove => "4.4",
+    );
     if ( $self->Told ) {
         return $self->ToldObj->AsString();
     }
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 1972067..b6c7308 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1232,8 +1232,7 @@ sub UpdateCustomFields {
     # while giving us something saner.
     my $args;
     if ($args{'ARGSRef'}) {
-        # XXX: deprecated, remove in 4.4
-        $RT::Logger->warning("Passing an ARGSRef to UpdateCustomFields is deprecated, and will be removed in RT 4.4; pass its contents instead");
+        RT->Deprecated( Arguments => "ARGSRef", Remove => "4.4" );
         $args = $args{ARGSRef};
     } else {
         $args = \%args;
diff --git a/share/html/Articles/Article/Elements/EditLinks b/share/html/Articles/Article/Elements/EditLinks
index 0328d93..996033c 100644
--- a/share/html/Articles/Article/Elements/EditLinks
+++ b/share/html/Articles/Article/Elements/EditLinks
@@ -65,7 +65,7 @@
 <li>
 <input type="checkbox" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" />
 %     if ($link->TargetURI->IsLocal) {
-<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->ObjectTypeStr) %> <%$member->Object->Id%></a>: 
+<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->RecordType) %> <%$member->Object->Id%></a>: 
 %       if (UNIVERSAL::isa($member->Object, "RT::Article") or UNIVERSAL::can($member->Object, 'Name')) {
 <%$member->Object->Name%>
 %       } elsif (UNIVERSAL::isa($member->Object, "RT::Ticket") or UNIVERSAL::can($member->Object, 'Subject')) {
@@ -92,7 +92,7 @@
 <li>
 <input type="checkbox" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" />
 %     if ($link->BaseURI->IsLocal) {
-<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->ObjectTypeStr) %> <%$member->Object->Id%>: 
+<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->RecordType) %> <%$member->Object->Id%>: 
 %       if (UNIVERSAL::isa($member->Object, "RT::Article") or UNIVERSAL::can($member->Object, 'Name')) {
 <%$member->Object->Name%>
 %       } elsif (UNIVERSAL::isa($member->Object, "RT::Ticket") or UNIVERSAL::can($member->Object, 'Subject')) {
diff --git a/share/html/Articles/Article/Elements/ShowLinks b/share/html/Articles/Article/Elements/ShowLinks
index 2e48ac9..bd4107f 100644
--- a/share/html/Articles/Article/Elements/ShowLinks
+++ b/share/html/Articles/Article/Elements/ShowLinks
@@ -53,7 +53,7 @@
 % my $member = $link->TargetURI;
 <li>
 % if ($link->TargetURI->IsLocal) {
-<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->ObjectTypeStr) %> <%$member->Object->Id%>: 
+<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->RecordType) %> <%$member->Object->Id%>: 
 % if (UNIVERSAL::isa($member->Object, "RT::Article") or UNIVERSAL::can($member->Object, 'Name')) {
 <%$member->Object->Name%>
 % } elsif (UNIVERSAL::isa($member->Object, "RT::Ticket") or UNIVERSAL::can($member->Object, 'Subject')) {
@@ -74,7 +74,7 @@
 % my $member = $link->BaseURI;
 <li>
 % if ($member->IsLocal) {
-<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->ObjectTypeStr) %> <%$member->Object->Id%>: 
+<a href="<%$member->Resolver->HREF%>"><% loc($member->Object->RecordType) %> <%$member->Object->Id%>: 
 % if (UNIVERSAL::isa($member->Object, "RT::Article") or UNIVERSAL::can($member->Object, 'Name')) {
 <%$member->Object->Name%>
 % } elsif (UNIVERSAL::isa($member->Object, "RT::Ticket") or UNIVERSAL::can($member->Object, 'Subject')) {
diff --git a/share/html/Elements/Callback b/share/html/Elements/Callback
index bd48bc5..1704aaf 100644
--- a/share/html/Elements/Callback
+++ b/share/html/Elements/Callback
@@ -48,6 +48,9 @@
 <%INIT>
 $ARGS{'CallbackPage'} = delete $ARGS{'Page'} || $m->callers(1)->path;
 $ARGS{'CallbackName'} = delete $ARGS{'_CallbackName'};
-$RT::Logger->debug("$ARGS{'CallbackPage'} calls old style callback, use \$m->callback");
+RT->Deprecated(
+    Instead => '$m->callback',
+    Remove => "4.4",
+);
 return $m->callback( %ARGS );
 </%INIT>
diff --git a/share/html/Ticket/Elements/EditCustomFields b/share/html/Ticket/Elements/EditCustomFields
index 1a0b222..659c866 100644
--- a/share/html/Ticket/Elements/EditCustomFields
+++ b/share/html/Ticket/Elements/EditCustomFields
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
-$RT::Logger->warning("DEPRECATED: use /Elements/EditCustomFields");
+RT->Deprecated( Remove => "4.4", Instead => "/Elements/EditCustomFields" );
 
 my $CustomFields;
 if ($TicketObj && !$OnCreate) {
diff --git a/share/html/Ticket/Elements/LoadTextAttachments b/share/html/Ticket/Elements/LoadTextAttachments
index a295f15..f102a6c 100644
--- a/share/html/Ticket/Elements/LoadTextAttachments
+++ b/share/html/Ticket/Elements/LoadTextAttachments
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
-# DEPRECATED: use the method below directly
+RT->Deprecated( Remove => "4.4", Instead => "RT::Ticket->TextAttachments" );
 return $Ticket->TextAttachments;
 </%INIT>
 <%ARGS>
diff --git a/t/api/record.t b/t/api/record.t
index 4b6b0b8..7abd41c 100644
--- a/t/api/record.t
+++ b/t/api/record.t
@@ -16,8 +16,8 @@ ok (require RT::Record);
 
 my $ticket = RT::Ticket->new(RT->SystemUser);
 my $group = RT::Group->new(RT->SystemUser);
-is($ticket->ObjectTypeStr, 'Ticket', "Ticket returns correct typestring");
-is($group->ObjectTypeStr, 'Group', "Group returns correct typestring");
+is($ticket->RecordType, 'Ticket', "Ticket returns correct typestring");
+is($group->RecordType, 'Group', "Group returns correct typestring");
 
 
 }

-----------------------------------------------------------------------


More information about the Rt-commit mailing list