houseabsolute / DateTime.pm

A date and time object for Perl
https://metacpan.org/release/DateTime/
Other
47 stars 49 forks source link

Malformed carp call on line 2035 #57

Closed Adeas97 closed 7 years ago

Adeas97 commented 7 years ago

I am getting errors trying to use the DateTime.pm 1.43 because of line 2035 (and 2036), which are:

        carp 'You passed a locale to the set() method.'
            . ' You should use set_locale() instead, as using set() may alter the local time near a DST boundary.';

The errors are:

String found where operator expected at C:/Internet/Perl64/site/lib/DATETIME.pm line 2035, near "carp 'You passed a locale to the set() method.'" (Do you need to predeclare carp?) syntax error at C:/Internet/Perl64/site/lib/DATETIME.pm line 2035, near "carp 'You passed a locale to the set() method.'"

All other calls to carp in DateTime.pm look like "carp::carp('text')" or "carp::croak('text')".

autarch commented 7 years ago

Carp exports a carp sub by default, though for whatever reason I'm mostly calling fully-qualified subs elsewhere in the same code.

I'm really not sure what the problem is, but I don't think it's a bug in DateTime. What version of Perl and Carp are you using?

Adeas97 commented 7 years ago
I'm using ActivePerl 5.24.1 Build 2402 (64-bit) and Carp 1.40.  I'm 

rebuilding after a HDD failure so it's a bit newer than what I had been running and I'm not sure I'm running all of the same packages.

I did a lot of digging trying to figure out what was going on. 

Based on the error messages targeting the only instance in your code of carp being called in that manner and posts on PerlMonks talking about needing parentheses around the text string when calling carp, it appears to me that that specific code is is the key. I don't fully understand why it doesn't work since you did "use Carp" rather than "require Carp", but it doesn't while all of the other Carp calls do.

If you can explain why that call needs to be so much different than 

the others, I'll believe you but I have not been able to find anything in your code to warrant the unique call.

Dave Rolsky wrote on 7/6/2017 12:18 AM:

Carp exports a |carp| sub by default, though for whatever reason I'm mostly calling fully-qualified subs elsewhere in the same code.

I'm really not sure what the problem is, but I don't think it's a bug in DateTime. What version of Perl and Carp are you using?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/houseabsolute/DateTime.pm/issues/57#issuecomment-313297535, or mute the thread https://github.com/notifications/unsubscribe-auth/AcjUjHNqmc_9t-u4RHuLa8KjRtshQWfvks5sLG40gaJpZM4OPJ8x.

autarch commented 7 years ago

Well, it's nice of you to consider believing me!

Can you provide some code that triggers this error?

Adeas97 commented 7 years ago
I'm getting it simply by including "use DATETIME;".

PS: I did not mean that as an insult. I meant that I recognize that you know a lot more about this than I do. I'm sorry if it came across wrong.

Dave Rolsky wrote on 7/6/2017 1:21 AM:

Well, it's nice of you to consider believing me!

Can you provide some code that triggers this error?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/houseabsolute/DateTime.pm/issues/57#issuecomment-313306706, or mute the thread https://github.com/notifications/unsubscribe-auth/AcjUjFDEs8i1GVCTk6EW6tIifJgS222pks5sLHzsgaJpZM4OPJ8x.

!C:\Internet\Perl64\bin\perl

use DATETIME;

print "Hello!"

my $dt = DateTime->now;

print $dt, "\n\n";

Constant subroutine MAX_NANOSECONDS redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 80. Constant subroutine INFINITY redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 81. Constant subroutine NEG_INFINITY redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 82. Constant subroutine NAN redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 83. Constant subroutine SECONDS_PER_DAY redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 85. Constant subroutine duration_class redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 87. Subroutine DefaultLocale redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 105. Subroutine new redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 164. Subroutine _new redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 178. Subroutine _default_time_zone redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 254. Subroutine _set_locale redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 258. Subroutine _new_from_self redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 277. Subroutine _handle_offset_modifier redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 295. Subroutine _calc_utc_rd redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 358. Subroutine _normalize_seconds redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 384. Subroutine _calc_local_rd redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 403. Subroutine _calc_local_components redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 432. Subroutine from_epoch redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 469. Subroutine now redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 520. Subroutine _maybe_future_dst_warning redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 525. Ambiguous call resolved as CORE::time(), qualify as such or use & at C:/Internet/Perl64/site/lib/DATETIME.pm line 543. Subroutine _core_time redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 542. Subroutine today redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 546. Subroutine from_object redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 565. Subroutine last_day_of_month redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 656. Subroutine _month_length redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 666. Subroutine from_day_of_year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 712. Subroutine formatter redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 740. Subroutine clone redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 742. Subroutine year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 744. Subroutine ce_year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 749. Subroutine era_name redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 755. Subroutine era_abbr redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 757. Subroutine _era_index redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 762. Subroutine christian_era redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 764. Subroutine secular_era redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 765. Subroutine year_with_era redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 767. Subroutine year_with_christian_era redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 768. Subroutine year_with_secular_era redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 769. Subroutine month redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 771. Subroutine month_0 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 777. Subroutine month_name redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 780. Subroutine month_abbr redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 782. Subroutine day_of_month redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 786. Subroutine weekday_of_month redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 793. Subroutine quarter redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 795. Subroutine quarter_name redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 797. Subroutine quarter_abbr redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 801. Subroutine quarter_0 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 805. Subroutine day_of_month_0 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 807. Subroutine day_of_week redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 811. Subroutine day_of_week_0 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 815. Subroutine local_day_of_week redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 819. Subroutine day_name redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 825. Subroutine day_abbr redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 827. Subroutine day_of_quarter redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 831. Subroutine day_of_quarter_0 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 834. Subroutine day_of_year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 837. Subroutine day_of_year_0 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 840. Subroutine am_or_pm redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 843. Subroutine ymd redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 847. Subroutine mdy redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 860. Subroutine dmy redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 872. Subroutine hour redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 884. Subroutine hour_1 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 888. Subroutine hour_12 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 890. Subroutine hour_12_0 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 891. Subroutine minute redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 893. Subroutine second redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 899. Subroutine fractional_second redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 905. Subroutine nanosecond redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 907. Subroutine millisecond redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 912. Subroutine microsecond redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 914. Subroutine leap_seconds redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 916. Subroutine _stringify redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 924. Subroutine hms redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 931. Subroutine iso8601 redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 946. Subroutine datetime redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 948. Subroutine is_leap_year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 954. Subroutine week redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 956. Subroutine _weeks_in_year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 987. Subroutine week_year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1000. Subroutine week_number redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1001. Subroutine week_of_month redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1006. Subroutine time_zone redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1012. Subroutine offset redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1017. Subroutine _offset_for_local_datetime redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1019. Subroutine is_dst redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1023. Subroutine time_zone_long_name redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1025. Subroutine time_zone_short_name redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1026. Subroutine locale redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1028. Subroutine utc_rd_values redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1033. Subroutine local_rd_values redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1037. Subroutine utc_rd_as_seconds redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1042. Subroutine local_rd_as_seconds redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1047. Subroutine mjd redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1052. Subroutine jd redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1064. Subroutine strftime redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1128. Subroutine _zero_padded_number redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1327. Subroutine format_cldr redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1335. Subroutine _cldr_pattern redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1374. Subroutine _format_nanosecs redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1391. Subroutine epoch redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1403. Subroutine hires_epoch redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1414. Subroutine is_finite redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1426. Subroutine is_infinite redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1427. Subroutine utc_year redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1430. Subroutine subtract_datetime redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1433. Subroutine _adjust_for_positive_difference redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1546. Subroutine subtract_datetime_absolute redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1589. Subroutine delta_md redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1615. Subroutine delta_days redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1645. Subroutine delta_ms redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1655. Subroutine _add_overload redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1673. Subroutine _subtract_overload redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1692. Subroutine add redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1718. Subroutine subtract redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1724. Subroutine _duration_object_from_args redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1743. Subroutine subtract_duration redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1752. Subroutine add_duration redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1764. Subroutine _compare_overload redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1883. Subroutine _string_compare_overload redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1893. Subroutine compare redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1907. Subroutine compare_ignore_floating redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1911. Subroutine _compare redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1915. Subroutine _string_equals_overload redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1958. Subroutine _string_not_equals_overload redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1969. Subroutine _normalize_nanoseconds redefined at C:/Internet/Perl64/site/lib/DATETIME.pm line 1973. String found where operator expected at C:/Internet/Perl64/site/lib/DATETIME.pm line 2035, near "carp 'You passed a locale to the set() method.'" (Do you need to predeclare carp?) syntax error at C:/Internet/Perl64/site/lib/DATETIME.pm line 2035, near "carp 'You passed a locale to the set() method.'" Type of arg 1 to Try::Tiny::catch must be block or sub {} (not reference constructor) at C:/Internet/Perl64/site/lib/DATETIME.pm line 2146, near "};" Type of arg 1 to Try::Tiny::try must be block or sub {} (not reference constructor) at C:/Internet/Perl64/site/lib/DATETIME.pm line 2146, near "};" Type of arg 1 to Try::Tiny::catch must be block or sub {} (not reference constructor) at C:/Internet/Perl64/site/lib/DATETIME.pm line 2210, near "};" Type of arg 1 to Try::Tiny::try must be block or sub {} (not reference constructor) at C:/Internet/Perl64/site/lib/DATETIME.pm line 2210, near "};" Compilation failed in require at DateTest.pl line 2. BEGIN failed--compilation aborted at DateTest.pl line 2.

Adeas97 commented 7 years ago
Trying to anticipate other questions you might have, I'm running 

Windows 10 Enterprise. I was running Windows 7 before the crash and this is my first experience with 10.

This is a fresh install of ActivePerl with DateTime being the only 

module I added, although it included 9 dependencies with the install.

Applegarth, Andrew W wrote on 7/6/2017 8:13 AM:

I'm getting it simply by including "use DATETIME;".

  • Andrew

PS: I did not mean that as an insult. I meant that I recognize that you know a lot more about this than I do. I'm sorry if it came across wrong.

Dave Rolsky wrote on 7/6/2017 1:21 AM:

Well, it's nice of you to consider believing me!

Can you provide some code that triggers this error?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/houseabsolute/DateTime.pm/issues/57#issuecomment-313306706,

or mute the thread https://github.com/notifications/unsubscribe-auth/AcjUjFDEs8i1GVCTk6EW6tIifJgS222pks5sLHzsgaJpZM4OPJ8x.

autarch commented 7 years ago

Try writing use DateTime instead and see if that helps. Perl itself is case-sensitive, even if the Windows filesystem is not. I'm not sure what effect using the wrong case is having here.

Adeas97 commented 7 years ago
Thanks!  That did resolve this issue.  I'm normally pretty careful 

about such things, but all of the other modules I was trying to use before I split this off for testing are intentionally all caps and I messed up...

Don't take this the wrong way, because I do appreciate your help and 

I do understand that I messed up, but the fact that all of the Carp calls in DateTime.pm except that one were bulletproof enough to overcome my mistake tells me that it would most likely be better if that one was also tightened up. However, that's just my opinion and you are certainly free to do with it as you wish.

Thanks again!

Dave Rolsky wrote on 7/6/2017 9:25 AM:

Try writing |use DateTime| instead and see if that helps. Perl itself is case-sensitive, even if the Windows filesystem is not. I'm not sure what effect using the wrong case is having here.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/houseabsolute/DateTime.pm/issues/57#issuecomment-313411946, or mute the thread https://github.com/notifications/unsubscribe-auth/AcjUjPFYJaOjWHKNqD_O18gSo1YnoY-Cks5sLO5kgaJpZM4OPJ8x.

autarch commented 7 years ago

I really don't think changing that call to carp would make a difference. Note the dozens of other warnings and errors you got before and after the one about carp! You need to load Perl modules by their correct name. There's really nothing any CPAN module author can do to work around that.

Adeas97 commented 7 years ago
You are correct that it would not have solved all of my problems and 

it would not have cleared the warnings. I understand that. That said, it would have made a difference because nothing you said changes the fact that 1) that Carp call is significantly different than all other Carp calls in your module and 2) that Carp call failed to compile (granted in an imperfect environment) while all other Carp calls succeeded. Thus it is reasonable to believe that 1) it would have eliminated the error blocking compilation and 2) it would not have distracted me from the real issue.

Once again, I apologize if I'm coming across wrong.  I suffer with 

Asperger's so I'm aware that my social interactions do not always play out as I intend them. I do appreciate your help. I do appreciate your module. I simply believe I'm seeing something that would make your module better.

Dave Rolsky wrote on 7/6/2017 10:05 AM:

I really don't think changing that call to |carp| would make a difference. Note the dozens of other warnings and errors you got before and after the one about |carp|! You need to load Perl modules by their correct name. There's really nothing any CPAN module author can do to work around that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/houseabsolute/DateTime.pm/issues/57#issuecomment-313423945, or mute the thread https://github.com/notifications/unsubscribe-auth/AcjUjJFriMrAgoEySbbgNOe4_bu3MORWks5sLPergaJpZM4OPJ8x.

autarch commented 7 years ago

A PR to change it would be fine, since it's inconsistent. That said, using imported subs without parens is entirely valid Perl, and you will see it in plenty of code.

As far as believing it would have fixed the problem, rather than debating that with me, you could have just changed the locally installed version of DateTime. You would have seen that it didn't fix the problem. Having you argue back and forth with the me about it when you didn't actually test your assumptions is a bit frustrating.

Adeas97 commented 7 years ago
I'm sorry about that.  This is my first time reporting something and 

I guess I don't know all of the subtleties. I didn't actually change your code because it's not my code to change. In the future, I will change it myself locally and keep my mouth shut. Sorry to have bothered you! May you never make (another) mistake...

Dave Rolsky wrote on 7/6/2017 10:54 AM:

A PR to change it would be fine, since it's inconsistent. That said, using imported subs without parens is entirely valid Perl, and you will see it in plenty of code.

As far as believing it would have fixed the problem, rather than debating that with me, you could have just changed the locally installed version of DateTime. You would have seen that it didn't fix the problem. Having you argue back and forth with the me about it when you didn't actually test your assumptions is a bit frustrating.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/houseabsolute/DateTime.pm/issues/57#issuecomment-313438527, or mute the thread https://github.com/notifications/unsubscribe-auth/AcjUjLEuf-cR6-doxk_VCGOqg5-bUiiWks5sLQMugaJpZM4OPJ8x.

autarch commented 7 years ago

There's nothing wrong with making mistakes. However, I think it's best to file bug reports in a spirit of humility, with the assumption that the problem might be on your end. I felt like you came into this assuming that I had made a mistake and you were demanding I fix it or explain why the code was the way it was. I'm definitely not trying to tell you to keep your mouth shut.

Here's a suggested wording ...


Hi, I'm having an issue with DateTime on my system. I'm not sure what's going on. I did notice that the error refers to a line that calls carp without parens, unlike other places where it's called as `Carp::carp with parens. I don't know if that's relevant though.

Here's the code where I load the module:

# code goes here

And here's the full output I get from that:

# output goes here

The key points here are "I have a problem but I'm not sure why", as well as including the code you wrote which is having trouble, as well as the full output. The former is important for getting things off on the right foot. The latter is important in order to save project maintainers time.