PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|DateTime|TimeZone|Local.pm =

page 1 of 3



package DateTime::TimeZone::Local;

use strict;
use warnings;

use vars qw( $VERSION );
$VERSION = '0.01';

use DateTime::TimeZone;
use File::Spec;


sub TimeZone
{
    my $class = shift;

    my $subclass = $class->_load_subclass();

    for my $meth ( $subclass->Methods() )
    {
	my $tz = $subclass->$meth();

	return $tz if $tz;
    }

    die "Cannot determine local time zone\n";
}

{
    # Stolen from File::Spec. My theory is that other folks can write
    # the non-existent modules if they feel a need, and release them
    # to CPAN separately.
    my %subclass = ( MSWin32 => 'Win32',
                     VMS     => 'VMS',
                     MacOS   => 'Mac',
                     os2     => 'OS2',
                     epoc    => 'Epoc',
                     NetWare => 'Win32',
                     symbian => 'Win32',
                     dos     => 'OS2',
                     cygwin  => 'Unix',
                   );

    sub _load_subclass
    {
        my $class = shift;

        my $subclass = $class . '::' . ( shift || $subclass{ $^O } || 'Unix' );

        return $subclass if $subclass->can('Methods');

        eval "use $subclass";
        if ($@)
        {
            if ( $@ =~ /locate/ )
            {
                $subclass = $class . '::' . 'Unix';

                eval "use $subclass";
                die $@ if $@;
            }
            else
            {
                die $@;
            }
        }

        return $subclass;
    }
}

sub FromEnv
{
    my $class = shift;

    foreach my $var ( $class->EnvVars() )
    {
	if ( $class->_IsValidName( $ENV{$var} ) )
	{
	    my $tz;
            {
                local $@;
                $tz = eval { DateTime::TimeZone->new( name => $ENV{$var} ) };
            }
            return $tz if $tz;
	}
    }

    return;
}

sub _IsValidName
{
    shift;

    return 0 unless defined $_[0];
    return 0 if $_[0] eq 'local';

    return $_[0] =~ m{^[\w/\-\+]+$};
}
=1=

= PAGE 1 = NEXT > |2|3

UP TO ROOT | UP TO DIR

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00546002 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)