[Koha-patches] [PATCH] more readable version of the init and new sub

Galen Charlton galen.charlton at liblime.com
Tue Apr 28 13:59:38 CEST 2009


Hi Marc,

Please make another attempt - I agree that your version of init() is
better, but the patch as submitted removes the output() method and
fails the test cases in t/Dates.t:

Can't locate object method "output" via package "C4::Dates" at
/home/gmc/koha/dev/C4/Dates.pm line 185.

Regards,

Galen

On Thu, Jan 15, 2009 at 7:18 PM, Marc Chantreux
<marc.chantreux at biblibre.com> wrote:
> ---
>  C4/Dates.pm |   48 ++++++++++++++++++++++++++++++------------------
>  1 files changed, 30 insertions(+), 18 deletions(-)
>
> diff --git a/C4/Dates.pm b/C4/Dates.pm
> index 7563b51..6c753a3 100644
> --- a/C4/Dates.pm
> +++ b/C4/Dates.pm
> @@ -116,27 +116,39 @@ sub _chron_to_hms {
>  }
>
>  sub new {
> -       my $this = shift;
> -       my $class = ref($this) || $this;
> -       my $self = {};
> -       bless $self, $class;
> -       return $self->init(@_);
> +    shift; # as clone isn't implemented, we don't carre about package name
> +    my $self = bless {}, __PACKAGE__;
> +    $self->init(@_)
>  }
> +
>  sub init ($;$$) {
> -       my $self = shift;
> -       my $dformat;
> -       $self->{'dateformat'} = $dformat = (scalar(@_) >= 2) ? $_[1] : _prefformat();
> -       ($format_map{$dformat}) or croak
> -               "Invalid date format '$dformat' from " . ((scalar(@_) >= 2) ? 'argument' : 'system preferences');
> -       $self->{'dmy_arrayref'} = [((@_) ? $self->dmy_map(shift) : localtime )] ;
> -       $debug and warn "(during init) \@\$self->{'dmy_arrayref'}: " . join(' ',@{$self->{'dmy_arrayref'}}) . "\n";
> -       return $self;
> -}
> -sub output ($;$) {
> -       my $self = shift;
> -       my $newformat = (@_) ? _recognize_format(shift) : _prefformat();
> -       return (eval {POSIX::strftime($posix_map{$newformat}, @{$self->{'dmy_arrayref'}})} || undef);
> +    my ($self,$string_date,$dformat) = @_;
> +
> +    my $from;
> +    if ( $dformat ) {
> +        $from = 'argument';
> +    } else {
> +        $from    = 'system preferences';
> +        $dformat = _prefformat;
> +    }
> +
> +    $self->{'dateformat'} = $dformat;
> +    $format_map{$dformat} or croak "Invalid date format '$dformat' from $from";
> +
> +    $self->{'dmy_arrayref'} = $string_date
> +       ? $self->dmy_map($string_date)
> +       : localtime
> +    ;
> +
> +    $debug and warn
> +        q[(during init) @$self->{'dmy_arrayref'}:]
> +        , join(' ',@{$self->{'dmy_arrayref'}})
> +        , "\n"
> +    ;
> +
> +    return $self;
>  }
> +
>  sub today ($;$) {              # NOTE: sets date value to today (and returns it in the requested or current format)
>        my $class = shift;
>        $class = ref($class) || $class;
> --
> 1.5.6.5
>
> _______________________________________________
> Koha-patches mailing list
> Koha-patches at lists.koha.org
> http://lists.koha.org/mailman/listinfo/koha-patches
>



-- 
Galen Charlton
VP, Research & Development, LibLime
galen.charlton at liblime.com
p: 1-888-564-2457 x709
skype: gmcharlt



More information about the Koha-patches mailing list