Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed warnings #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fixed warnings #15

wants to merge 1 commit into from

Conversation

forwardever
Copy link

I got this mail from the author of Devel::TrackObjects regarding strange warnings:

Hi,

$tracked->[0] is the object itself.

If you print it it will stringify it. Stringification is overloaded
in Date::Time using Date::Time::_stringify, which will use ymd and hms
to stringify the object.

If the Date::Time object itself contains no $self->{local_c} yet the
values for sprintf in ymd and hms will be undef which causes the
warnings.

So this is not really a bug in DateTime, because they never intended
for somebody to stringify some internal objects. But it's not a bug
in Devel::TrackObjects either.
Let's just say, they are not made to work close together.

But I've worked now around this overloading when debugging is enabled
(just released 0.5, see https://github.com/noxxi/p5-devel-trackobjects)
and so can you:

+ use overload;
...
-      warn $tracked->[0];
+      warn overload::StrVal($tracked->[0]);

@miyagawa
Copy link
Owner

miyagawa commented Feb 5, 2013

This issues misses the context - What is the original problem you had?

@forwardever
Copy link
Author

I have created a simple test case, so the following code produces lots of warnings, or when it comes to plack middleware debug, I get a bunch of warnings with every request in my console window:

warning:
Use of uninitialized value in sprintf at C:/strawberry/perl/site/lib/DateTime.pm line 766

test case:

sub import {
    use Devel::TrackObjects qr/^/;
}

use DateTime;

my $dt = DateTime->now;
$dt->set_time_zone('UTC');
$dt->set_time_zone('Europe/Paris');
print "Hello World";

my $tracked = Devel::TrackObjects->show_tracked_detailed;

foreach my $tracked (@$tracked) {
    warn $tracked->[0];
}

which is fixed by

use overload;

sub import {
    use Devel::TrackObjects qr/^/;
}

use DateTime;

my $dt = DateTime->now;
$dt->set_time_zone('UTC');
$dt->set_time_zone('Europe/Paris');
print "Hello World";

my $tracked = Devel::TrackObjects->show_tracked_detailed;

foreach my $tracked (@$tracked) {
    warn overload::StrVal($tracked->[0]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants