On 03/08/2012 12:35 PM, sb...@cpan.org wrote:
> On 03/08/2012 02:53 PM, Bruce Ferrell wrote:
>> Just thought I'd share with the group and experience I just had.  In perhaps 
>> the hope of sparing others of the PITA I just went through.
>>
>> First of all, I will acknowledge I am perhaps not the best of programmers... 
>> Perhaps being an understatement.
>>
>> Second of all, it is not a request for a "better way to code" this.  This is 
>> a recounting of some troubleshooting I just endured due to a programmer very 
>> much more clever than I.
>>
>> First, allow me to present the offender(s):
>>
>> sub timestamp {
>>          return strftime( "%Y-%m-%d %H:%M:%S", gmtime($_[0] || time()) );
>> }
>>
>> my $ts0 = UnixDate( Date_ConvTZ( ParseDate( timestamp() 
>> ),"GMT",$tz),"%Y-%m-%d %T" );
>>
>> The original environment for this code is a Linux system running Perl 5.8.8 
>> and it performed flawlessly there and was successfully transplanted to 
>> 5.10.0 with no changes needed.
>> When the application containing the code above was transplanted to a system 
>> running Perl 5.12.3... Well, lets just say this is where the fun began.
>>
>> When it comes to Perl installations, I long ago learned not to trust 
>> Distribution provided modules so I always use CPAN to install from.  Basic 
>> Perl, from the Distro, sure... Add
>> on modules, not so much.  Often the modules I want aren't even in the distro 
>> and for module sets I use often I have little shell scripts to load the 
>> necessary modules from CPAN.  I
>> don't really look at it that much.  Maybe not the best practice, but I'm 
>> busy.  I also want to say, this is code a wrote a couple of years ago.  I've 
>> not touched it since and have
>> since moved on to other things.
>>
>> When the report came in that important function weren't working I first had 
>> to find the location of the failing code.  Is it being passed it's necessary 
>> data.  Yep... OK, so what's
>> wrong?  Any errors thrown?  Nope.  OK, extract the code into a test program 
>> (below, suitably "cleaned" to disguise what it really is).  "In circuit" the 
>> code runs as a daemon and
>> errors aren't easy to get at.
>>
>> #!/usr/bin/perl -w
>>
>> use lib '../lib';
>>
>> use Common;  # contains timestamp()
>>
>> use Date::Manip;
>>
>> my $graphdates='';
>>
>>          $graphdates .= "&action=plot&ts2=" .  UnixDate( Date_ConvTZ( 
>> ParseDate( timestamp() ),"GMT",$tz),"%Y-%m-%d %T" );
>>          $graphdates .= "&ts=" . UnixDate( Date_ConvTZ(DateCalc( ParseDate( 
>> timestamp() ), "- 120 Minutes" ),"GMT",$tz),"%Y-%m-%d %T" );
>>          my $test = UnixDate( Date_ConvTZ( ParseDate( timestamp() 
>> ),"GMT",$tz),"%Y-%m-%d %T" );
>>
>> print STDERR "$test\n"
>>
>>
>> In the test program, the conversion stream works correctly.  OK... Now what? 
>>  Maybe the module didn't install correctly?!  Hand install with UNINST=1 set
>>
>> The application still misbehaves but now I have the all distribution files 
>> so I dig into the docs where I find this:
>>
>> FUNCTIONAL INTERFACE (VERSION 5)
>>      When using a version of perl older than 5.10, this is the only interface
>>      available. This interface is documented in the Date::Manip::DM5
>>      document.
>>
>> (The above should read 5.10 and below, because the code worked exactly as it 
>> did under 5.8.8 at 5.10.0)
>>
>> and this:
>>
>>      DATE_MANIP ENVIRONMENT VARIABLE
>>          By setting the DATE_MANIP environment variable to 'DM5' before
>>          running the perl script, the version 5 interface will be used.
>>
>> suffice to say, problem solved!
>>
>> insert
>>
>>      export DATE_MANIP=DM5
>>
>> into the daemon startup script and enable mod_env in the apache that runs 
>> other parts, adding
>>
>>      SetEnv DATE_MANIP DM5
>>
>> to the apache config file.
>>
>> Now here comes my question:
>>
>> Shouldn't this have thrown SOME kind of error/warning what was going on?  Is 
>> silent failure a proper behavior no matter how clever the switch around is? 
>> Just asking.
>>
>> Respectfully,
>> Bruce Ferrell
>
> Your report is long... but it unfortunately doesn't contain much information 
> on what failed or why.
>
> When I run your script (with the addition of the line setting $tz and a 
> couple prints):
>
>   #!/usr/bin/perl
>
>   use POSIX qw(strftime);
>   use Date::Manip;
>
>   sub timestamp {
>    return strftime( "%Y-%m-%d %H:%M:%S", gmtime($_[0] || time()) );
>   }
>
>   my $tz  = "America/New_York";
>
>   my $st  = timestamp();
>   print "$st\n";
>
>   my $ts0 = UnixDate( Date_ConvTZ( ParseDate( $st ),"GMT",$tz),"%Y-%m-%d %T" 
> );
>
>   print "$ts0\n";
>
> it seems to work fine.  You didn't tell me what $tz should be, so I just used 
> my local timezone, and the result of this is that it prints out the current 
> time (which is
> correct).  I ran it with both perl 5.10.1 and 5.14.2.
>
> So, I can't tell what you expected it to produce, or what it did produce 
> based on your report.  If you fill in some/all of this information, I may be 
> able to help more.
>
> However, I can provide a little information which may help.
>
> You've updated from Date::Manip 5.xx to 6.xx.  That's a major upgrade with a 
> few backwards incompatible changes (not many... but there are a couple).  You 
> may want to read the
> Date::Manip::Migration5to6 man page.  It talks about a change to the 
> Date_ConvTZ function, but it doesn't appear to me that that is what it 
> getting you since you are using 3
> arguments.  Still, there may be some change in there that's impacting you.
>
> Of course, you can use the the workaround of setting DATE_MANIP=DM5 (which 
> means that you continue to use the 5.xx version of Date::Manip), but if 
> you're doing any kind of
> timezone handling (which you are), you'd be well served to switch to 6.xx .  
> 5.xx does NOT handle timezones well.
>
> As far as your question:
>
>    shouldn't this have thrown SOME kind of error/waring
>
> the answer is:  I don't know since I can't be sure of what failed.  Frankly, 
> if Date_ConvTZ returns nothing, it means that there was an error on the 
> input, so if you check your
> return value, it DOES signal an error.  At that point, handling the error 
> really falls to the calling program... not the module, since I can't possibly 
> know what the result of an
> error should be.
>
>
> Anyway, if you want to provide me with some information about how this script 
> failed, I'll be happy to look into it more.
>
>

The failure, I thought was clear.  Nothing is is returned in the running code.  
In the test code on the "bad" system:

 ./test.pl

2012-03-08 13:07:25

I get a return?! BTW, the environment variable isn't set. See why I'm now 
squirrel bait?

cpan[1]> i Date::Manip
Reading '/root/.cpan/Metadata'
  Database was generated on Thu, 08 Mar 2012 07:13:59 GMT
Module id = Date::Manip
    DESCRIPTION  Complete date/time manipulation package
    CPAN_USERID  SBECK (Sullivan Beck <sb...@cpan.org>)
    CPAN_VERSION 6.31
    CPAN_FILE    S/SB/SBECK/Date-Manip-6.31.tar.gz
    UPLOAD_DATE  2012-03-01
    DSLIP_STATUS RdpOp (released,developer,perl,object-oriented,Standard-Perl)
    MANPAGE      Date::Manip - Date manipulation routines
    INST_FILE    /usr/lib/perl5/site_perl/5.12.3/Date/Manip.pm
    INST_VERSION 6.31


My apologies for the lack of information.    If $tz isn't defined, the function 
defaults to GMT. $tz is in fact a timezone entry, in the case of the failing 
system, "CST5CDT" and
that really works on 5.10.0 and below... with 5.4.

I just re-looked at the cpan entry on the "good" system

cpan[2]> i Date::Manip
Module id = Date::Manip
    DESCRIPTION  Complete date/time manipulation package
    CPAN_USERID  SBECK (Sullivan Beck <sb...@cpan.org>)n
    CPAN_VERSION 6.31
    CPAN_FILE    S/SB/SBECK/Date-Manip-6.31.tar.gz
    DSLIP_STATUS RdpOp (released,developer,perl,object-oriented,Standard-Perl)
    MANPAGE      Date::Manip - date manipulation routines
    INST_FILE    /usr/lib/perl5/vendor_perl/5.10.0/Date/Manip.pm
    INST_VERSION 5.54

You're right, I do have 5 installed there.  I blasted publicly, so I get to 
apologize just as publicly.  Mea Culpa.  My only excuse is coding/debugging 
from 2am my time and for
many days actually.  And that's a poor excuse too.

Since I didn't say it initially, I have to now.  Thanks for the code.  It DOES 
make my life better.

Respectfully,

Bruce Ferrell



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to