HTML-Menu-DateTime

 view release on metacpan or  search on metacpan

lib/HTML/Menu/DateTime.pm  view on Meta::CPAN

  }
  
  return \@val, $html;
}


sub _increment {
  my ($self, $type) = @_;
  
  my $inc = $self->{"${type}_increment"};
  
  croak("${type}_increment must be between 1 and 59")
    unless (($inc >= 1) && ($inc <= 59));
  
  my @num;
  
  for (my $i=0; $i<=59; $i+=$inc) {
    push @num, sprintf("%02d", $i);
  }
  
  return @num;
}


sub _html {
  my ($self, $select, $html, $loop) = @_;
  
  require HTML::Menu::Select;
  
  my %args = (
    values => [ map { $_->{value} } @$loop ],
    labels => { map { $_->{value} => $_->{label} } @$loop },
  );
  
  if (! $self->{no_select}) {
    $args{default} = $select;
  }
  
  if (defined $html) {
    $args{$_} = $html->{$_} for keys %$html;
  }
  
  
  if ($self->{html} eq 'menu') {
    return HTML::Menu::Select::menu( %args );
  }
  elsif ($self->{html} eq 'options') {
    return HTML::Menu::Select::options( %args );
  }
  else {
    croak "unknown html option";
  }
}

1;

__END__

=head1 NAME

HTML::Menu::DateTime - Easily create popup menus for use with templates.

=head1 SYNOPSIS

  use HTML::Menu::DateTime;
  
  my $menu = HTML::Menu::DateTime->new (
    date         => '2004-02-26',
    no_select    => 1,
    empty_first  => '');
  
  $menu->start_year (2000);
  $menu->end_year (2010);
  
  $menu->less_years (1);
  $menu->plus_years (5);
  
  $menu->month_format ('short');
  $menu->locale ('en_GB');
  $menu->second_increment (15);
  $menu->minute_increment (5);
  
  $menu->html ('menu');
  
  $menu->second_menu;
  $menu->minute_menu;
  $menu->hour_menu;
  $menu->day_menu;
  $menu->month_menu;
  $menu->year_menu;

=head1 DESCRIPTION

Creates data structures suitable for populating HTML::Template, 
Template Toolkit or Template::Magic templates with dropdown date and 
time menus.

Allows any number of dropdown menus to be displayed on a single page, each 
independantly configurable.

Distribution includes ready-to-use template include files. 

Can output valid HTML, allowing quick prototyping of pages, with the freedom 
to easily switch to using templates later. 

=head1 MOTIVATION

To keep the creation of HTML completely seperate from the program, to easily 
allow a non-programmer to add css styles, javascript, etc. to individual 
menus.

To make the creation of menus as simple as possible, with extra options if 
needed. HTML Menus can be created as easily as:

  my $template = HTML::Template->new (filename => $filename);
  
  my $menu = HTML::Menu::DateTime->new;
  
  $template->param (day   => $menu->day_menu,
                    month => $menu->month_menu,
                    year  => $menu->year_menu);



( run in 1.828 second using v1.01-cache-2.11-cpan-364913b4093 )