view release on metacpan or search on metacpan
MANIFEST
Makefile
Makefile.PL
lib/CGI/Application/Plugin/Menu.pm
lib/HTML/Template/Menu.pm
t/0.t
t/88_HTML-Template-Menu-withicon.t
t/99_HTML-Template-Menu.t
t/MTest.pm
META.yml Module meta-data (added by MakeMaker)
--- #YAML:1.0
name: CGI-Application-Plugin-Menu
version: 1.06
abstract: ~
author: []
license: perl
distribution_type: module
configure_requires:
ExtUtils::MakeMaker: 0
requires:
Carp: 1
CGI::Application: 4.06
# This Makefile is for the CGI::Application::Plugin::Menu extension to perl.
#
# It was generated automatically by MakeMaker version
# 6.48 (Revision: 64800) from the contents of
# Makefile.PL. Don't edit this file, edit Makefile.PL instead.
#
# ANY CHANGES MADE HERE WILL BE LOST!
#
# MakeMaker ARGV: ()
#
# MakeMaker Parameters:
# EXE_FILES => []
# LICENSE => q[perl]
# NAME => q[CGI::Application::Plugin::Menu]
# PREREQ_PM => { CGI::Application=>q[4.06], HTML::Template=>q[2.9], Test::Simple=>q[0], Exporter=>q[5], Smart::Comments=>q[1], LEOCHARRE::DEBUG=>q[1.13], Carp=>q[1] }
# VERSION_FROM => q[lib/CGI/Application/Plugin/Menu.pm]
# --- MakeMaker post_initialize section:
# --- MakeMaker const_config section:
# These definitions are from config.sh (via /usr/lib/perl5/5.8.8/i386-linux-thread-multi/Config.pm).
# They may have been overridden via Makefile.PL or on the command line.
AR = ar
CC = gcc
SITEARCHEXP = /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
SO = so
VENDORARCHEXP = /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
VENDORLIBEXP = /usr/lib/perl5/vendor_perl/5.8.8
# --- MakeMaker constants section:
AR_STATIC_ARGS = cr
DIRFILESEP = /
DFSEP = $(DIRFILESEP)
NAME = CGI::Application::Plugin::Menu
NAME_SYM = CGI_Application_Plugin_Menu
VERSION = 1.06
VERSION_MACRO = VERSION
VERSION_SYM = 1_06
DEFINE_VERSION = -D$(VERSION_MACRO)=\"$(VERSION)\"
XS_VERSION = 1.06
XS_VERSION_MACRO = XS_VERSION
XS_DEFINE_VERSION = -D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"
INST_ARCHLIB = blib/arch
INST_SCRIPT = blib/script
INST_BIN = blib/bin
MAKEMAKER = /usr/lib/perl5/5.8.8/ExtUtils/MakeMaker.pm
MM_VERSION = 6.48
MM_REVISION = 64800
# FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
# BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
# PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
# DLBASE = Basename part of dynamic library. May be just equal BASEEXT.
MAKE = make
FULLEXT = CGI/Application/Plugin/Menu
BASEEXT = Menu
PARENT_NAME = CGI::Application::Plugin
DLBASE = $(BASEEXT)
VERSION_FROM = lib/CGI/Application/Plugin/Menu.pm
OBJECT =
LDFROM = $(OBJECT)
LINKTYPE = dynamic
BOOTDEP =
# Handy lists of source code files:
XS_FILES =
C_FILES =
O_FILES =
H_FILES =
MAN1PODS =
MAN3PODS = lib/CGI/Application/Plugin/Menu.pm \
lib/HTML/Template/Menu.pm
# Where is the Config information that we are using/depend on
CONFIGDEP = $(PERL_ARCHLIB)$(DFSEP)Config.pm $(PERL_INC)$(DFSEP)config.h
# Where to build things
INST_LIBDIR = $(INST_LIB)/CGI/Application/Plugin
INST_ARCHLIBDIR = $(INST_ARCHLIB)/CGI/Application/Plugin
INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT)
INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT)
INST_STATIC =
INST_DYNAMIC =
INST_BOOT =
# Extra linker info
EXPORT_LIST =
PERL_ARCHIVE =
PERL_ARCHIVE_AFTER =
TO_INST_PM = lib/CGI/Application/Plugin/Menu.pm \
lib/HTML/Template/Menu.pm
PM_TO_BLIB = lib/HTML/Template/Menu.pm \
blib/lib/HTML/Template/Menu.pm \
lib/CGI/Application/Plugin/Menu.pm \
blib/lib/CGI/Application/Plugin/Menu.pm
# --- MakeMaker platform_constants section:
MM_Unix_VERSION = 6.48
PERL_MALLOC_DEF = -DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc -Dfree=Perl_mfree -Drealloc=Perl_realloc -Dcalloc=Perl_calloc
# --- MakeMaker tool_autosplit section:
# Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
AUTOSPLITFILE = $(ABSPERLRUN) -e 'use AutoSplit; autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)' --
COMPRESS = gzip --best
SUFFIX = .gz
SHAR = shar
PREOP = $(NOECHO) $(NOOP)
POSTOP = $(NOECHO) $(NOOP)
TO_UNIX = $(NOECHO) $(NOOP)
CI = ci -u
RCS_LABEL = rcs -Nv$(VERSION_SYM): -q
DIST_CP = best
DIST_DEFAULT = tardist
DISTNAME = CGI-Application-Plugin-Menu
DISTVNAME = CGI-Application-Plugin-Menu-1.06
# --- MakeMaker macro section:
# --- MakeMaker depend section:
# --- MakeMaker cflags section:
# --- MakeMaker static_lib section:
# --- MakeMaker manifypods section:
POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
POD2MAN = $(POD2MAN_EXE)
manifypods : pure_all \
lib/HTML/Template/Menu.pm \
lib/CGI/Application/Plugin/Menu.pm
$(NOECHO) $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) \
lib/HTML/Template/Menu.pm $(INST_MAN3DIR)/HTML::Template::Menu.$(MAN3EXT) \
lib/CGI/Application/Plugin/Menu.pm $(INST_MAN3DIR)/CGI::Application::Plugin::Menu.$(MAN3EXT)
# --- MakeMaker processPL section:
# --- MakeMaker installbin section:
- $(RM_F) \
$(MAKEFILE_OLD) $(FIRST_MAKEFILE)
- $(RM_RF) \
$(DISTVNAME)
# --- MakeMaker metafile section:
metafile : create_distdir
$(NOECHO) $(ECHO) Generating META.yml
$(NOECHO) $(ECHO) '--- #YAML:1.0' > META_new.yml
$(NOECHO) $(ECHO) 'name: CGI-Application-Plugin-Menu' >> META_new.yml
$(NOECHO) $(ECHO) 'version: 1.06' >> META_new.yml
$(NOECHO) $(ECHO) 'abstract: ~' >> META_new.yml
$(NOECHO) $(ECHO) 'author: []' >> META_new.yml
$(NOECHO) $(ECHO) 'license: perl' >> META_new.yml
$(NOECHO) $(ECHO) 'distribution_type: module' >> META_new.yml
$(NOECHO) $(ECHO) 'configure_requires:' >> META_new.yml
$(NOECHO) $(ECHO) ' ExtUtils::MakeMaker: 0' >> META_new.yml
$(NOECHO) $(ECHO) 'requires:' >> META_new.yml
$(NOECHO) $(ECHO) ' Carp: 1' >> META_new.yml
$(NOECHO) $(ECHO) ' CGI::Application: 4.06' >> META_new.yml
$(NOECHO) $(ECHO) ' <ARCHITECTURE NAME="i386-linux-thread-multi-5.8" />' >> $(DISTNAME).ppd
$(NOECHO) $(ECHO) ' <CODEBASE HREF="" />' >> $(DISTNAME).ppd
$(NOECHO) $(ECHO) ' </IMPLEMENTATION>' >> $(DISTNAME).ppd
$(NOECHO) $(ECHO) '</SOFTPKG>' >> $(DISTNAME).ppd
# --- MakeMaker pm_to_blib section:
pm_to_blib : $(TO_INST_PM)
$(NOECHO) $(ABSPERLRUN) -MExtUtils::Install -e 'pm_to_blib({@ARGV}, '\''$(INST_LIB)/auto'\'', '\''$(PM_FILTER)'\'')' -- \
lib/HTML/Template/Menu.pm blib/lib/HTML/Template/Menu.pm \
lib/CGI/Application/Plugin/Menu.pm blib/lib/CGI/Application/Plugin/Menu.pm
$(NOECHO) $(TOUCH) pm_to_blib
# --- MakeMaker selfdocument section:
# --- MakeMaker postamble section:
# End.
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'CGI::Application::Plugin::Menu',
VERSION_FROM => 'lib/CGI/Application/Plugin/Menu.pm',
# gen /usr/bin/pmused by Tue May 12 16:52:40 EDT 2009
PREREQ_PM => {
'CGI::Application' => '4.06',
'Carp' => '1',
'Exporter' => '5',
'HTML::Template' => '2.9',
'LEOCHARRE::DEBUG' => '1.13',
'Smart::Comments' => '1',
lib/CGI/Application/Plugin/Menu.pm view on Meta::CPAN
package CGI::Application::Plugin::Menu;
use strict;
use LEOCHARRE::DEBUG;
use warnings;
use Carp;
use Exporter;
use HTML::Template::Menu;
use vars qw(@ISA @EXPORT $VERSION);
@ISA = qw/ Exporter /;
@EXPORT = qw(menu ___menus_ ___menus_order menus menus_count menu_delete);
$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)/g;
sub menu {
my ($self,$label) = @_;
$label ||= 'main';
unless ( exists $self->___menus_->{$label} ) {
$self->___menus_->{$label} =
# new CGI::Application::Plugin::MenuObject;
new HTML::Template::Menu;
$self->___menus_->{$label}->name_set($label);
push @{$self->___menus_order},$label;
}
return $self->___menus_->{$label};
}
*menus = \&___menus_order;
sub ___menus_ {
$_[0]->{'__CGI::Application::Plugin::Menu::Objects'} ||={};
$_[0]->{'__CGI::Application::Plugin::Menu::Objects'};
}
sub ___menus_order {
$_[0]->{'__CGI::Application::Plugin::Menu::ObjectsOrder'} ||=[];
$_[0]->{'__CGI::Application::Plugin::Menu::ObjectsOrder'};
}
sub menus_count { scalar @{$_[0]->menus} }
sub menu_delete {
my $self = shift;
my $label = shift;
delete $self->___menus_->{$label};
my @order;
for my $menu_label ( @{$self->___menus_order} ){
$menu_label eq $label and next;
push @order, $menu_label;
}
$self->{'__CGI::Application::Plugin::Menu::ObjectsOrder'} = \@order;
1;
}
1;
__END__
=pod
=head1 NAME
CGI::Application::Plugin::Menu - manage navigation menus for cgi apps
=head1 SYNOPSIS
use base 'CGI::Application';
use CGI::Application::Plugin::Menu;
sub _get_menu_outputs {
my $self = shift;
my $html_output;
my $menu_main = $self->menu;
# resolves to a 'Home' link
$menu_main->add('/');
lib/CGI/Application/Plugin/Menu.pm view on Meta::CPAN
=head1 DESCRIPTION
This is a simple way of having menus in your cgi apps.
=head1 METHODS
=head2 menu()
if you don't provide an argument, the default is used, which is 'main'.
returns HTML::Template::Menu A MENU OBJECT object.
=head2 menus()
returns array ref of names of menus that exist now.
They are in the order that they were instanced
my $m0 = $self->menu('main');
$m0->add('home');
$m0->add('news');
lib/CGI/Application/Plugin/Menu.pm view on Meta::CPAN
for ( @{$self->menus} ){
my $m = $_;
my $menu_name = $m->name;
my $loop_for_html_template = $m->loop;
}
=head1 A MENU OBJECT
Are instances of HTML::Template::Menu
=head2 METHODS
=head3 name()
returns name of the menu.
=head3 add()
argument is url or runmode
lib/CGI/Application/Plugin/Menu.pm view on Meta::CPAN
=head3 loop()
get loop suitable for HTML::Template object
See SYNOPSIS.
=head2 output()
If you just want the output with the default hard coded template.
The default template code is stored in:
$HTML::Template::Menu::DEFAULT_TMPL
=head2 menu_delete()
Argument is menu label, deletes the menu.
Returns true, does not check for existance.
=head2 ADDING MENU ITEMS
my $m = $self->menu_get('main menu');
$m->add('home');
$m->add('http://helpme.com','Need help?');
$m->add('logout');
Elements for the menu are shown in the order they are inserted.
=head1 AUTOMATICALLY GENERATING A MENU
See CGI::Application::Plugin::AutoMenuitem
=head1 SEE ALSO
L<CGI::Application>
L<HTML::Template>
L<HTML::Template::Menu>
=head1 AUTHOR
Leo Charre leocharre at cpan dot org
=head1 LICENSE
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".
lib/HTML/Template/Menu.pm view on Meta::CPAN
package HTML::Template::Menu;
use strict;
use LEOCHARRE::DEBUG;
use warnings;
use Carp;
$HTML::Template::Menu::DEFAULT_TMPL = q{
<div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
<TMPL_LOOP MAIN_MENU_LOOP><nobr><b><a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
</TMPL_LOOP></p></div>};
sub new {
my $class = shift;
my $self = {};
bless $self,$class;
return $self;
lib/HTML/Template/Menu.pm view on Meta::CPAN
return 1;
}
sub _add_menu_item {
my ($self,$arg1,$url,$label,$icon) = @_;
my $hash = $self->_get_menuitems;
my $array = $self->_get_menuitems_order;
if (exists $hash->{$arg1}){
debug("Menu item [$arg1] was already entered. Skipped.\n");
return 0;
}
push @$array, $arg1;
$hash->{$arg1} = {
arg1 => $arg1,
url => $url,
label => $label,
lib/HTML/Template/Menu.pm view on Meta::CPAN
my $label = __prettify_string($val);
return $label;
}
sub output {
my $self = shift;
require HTML::Template;
my $tmpl = new HTML::Template(
die_on_bad_params => 0,
scalarref => \$HTML::Template::Menu::DEFAULT_TMPL,
)
or die('cant instance HTML::Template object');
$tmpl->param(
MAIN_MENU_LOOP => $self->loop,
MAIN_MENU_CLASS => $self->menu_class );
return $tmpl->output;
}
sub menu_class {
lib/HTML/Template/Menu.pm view on Meta::CPAN
}
1;
=pod
=head1 NAME
HTML::Template::Menu - ease menu items for quick web user interface
=head1 SYNOPSIS
use HTML::Template::Menu;
my $m = new HTML::Template::Menu;
$m->add('/','home');
$m->add('/contact.html');
$m->add('http://google.com');
$m->add('http://titantv.com', 'view tv listings');
print $m->output;
=head1 METHODS
=head2 new()
=head2 name()
Returns name of the menu.
=head2 name_set()
Sets name of menu, argument is string.
my $m = new HTML::Template::Menu;
$m->name_set('login_menu');
=head2 add()
Argument is url or CGI::Application runmode name.
Optional argument is a label, (the anchor text).
If the first argument has no funny chars, it is treated as a runmode, instead of a url.
The label is what will appear in the link text,
lib/HTML/Template/Menu.pm view on Meta::CPAN
=head2 menu_class_set()
Arg is string.
Sets the TMPL_VAR MAIN_MENU_CLASS css name. If not provided, one is generated for you.
=head2 output()
If you just want the output with the default hard coded template.
The default template code is stored in:
$CGI::Application::Plugin::MenuObject::DEFAULT_TMPL
=head1 ADDING MENU ITEMS
my $m = $self->menu_get('main menu');
$m->add('home');
$m->add('http://helpme.com','Need help?');
$m->add('logout');
lib/HTML/Template/Menu.pm view on Meta::CPAN
This is the default template:
<div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
<TMPL_LOOP MAIN_MENU_LOOP><nobr><b><a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
</TMPL_LOOP></p></div>
You can feed your own template with:
my $m = HTML::Template::Menu->new;
$m->add('http://cpan.org');
my $tmpl = HTML::Template->new( scalarref => \q{
<div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
<TMPL_LOOP MAIN_MENU_LOOP><nobr><b><a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
</TMPL_LOOP></p></div>
});
$tmpl->param( MENU_LOOP => $m->loop );
One other way to change it:
$HTML::Template::Menu::DEFAULT_TMPL = q{
<div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
<TMPL_LOOP MAIN_MENU_LOOP><nobr><b><img src="/gfx/bullet.png"> <a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
</TMPL_LOOP></p></div>
};
=head1 ICONS
Each menu item has the TMPL_VAR s set: LABEL, URL, ICON.
ICON is a broken down simplification of whatever was in the URL.
You may choose to use this to include icons.
For example:
my $m = HTML::Template::Menu->new;
$m->add('http://cpan.org');
my $tmpl = HTML::Template->new( scalarref => \q{
<div class="<TMPL_VAR MAIN_MENU_CLASS>"><p>
<TMPL_LOOP MAIN_MENU_LOOP><nobr><b><img src="/icons/<TMPL_VAR ICON>">
<a href="<TMPL_VAR URL>">[<TMPL_VAR LABEL>]</a></b></nobr>
</TMPL_LOOP></p></div>
});
$tmpl->param( MENU_LOOP => $m->loop );
lib/HTML/Template/Menu.pm view on Meta::CPAN
<nobr><b>
<img src="/.icons/cpan.png">
<a href="http://cpan.org">[Cpan]</a></b></nobr></p>
=head1 SEE ALSO
L<HTML::Template> - the excellent HTML::Template module.
L<CGI::Application::Plugin::Menu> - spinoff plugin for L<CGI::Application>.
=head1 AUTHOR
Leo Charre leocharre at cpan dot org
=head1 COPYRIGHT
Copyright (c) 2009 Leo Charre. All rights reserved.
use Test::Simple 'no_plan';
use strict;
use lib './lib';
use lib './t';
use MTest;
use Smart::Comments '###';
$CGI::Application::Plugin::Menu::DEBUG = 1;
my $a = new MTest;
ok($a,'instanced');
my $o = $a->menu;
ok($o,'got menu basic');
ok($o->name eq 'main', 'name is main');
t/88_HTML-Template-Menu-withicon.t view on Meta::CPAN
use Test::Simple 'no_plan';
use strict;
use lib './lib';
use HTML::Template::Menu;
use HTML::Template;
ok(1,'loaded');
my $m = new HTML::Template::Menu;
$m->name_set('Test Menu');
ok( $m->add('/') );
ok( $m->add('/contact.html') );
ok( $m->add('view_more'));
ok( $m->add('/doc/review_coorporate.html'));
ok( $m->add('/doc/review_coorporate.php?val1=this'));
ok( $m->add('/tips'));
$m->add('/cars/');
$m->add('http://cpan.org');
t/99_HTML-Template-Menu.t view on Meta::CPAN
use Test::Simple 'no_plan';
use strict;
use lib './lib';
use HTML::Template::Menu;
ok(1,'loaded');
my $m = new HTML::Template::Menu;
$m->name_set('Test Menu');
ok( $m->add('/') );
ok( $m->add('/contact.html') );
ok( $m->add('view_more'));
ok( $m->add('/doc/review_coorporate.html'));
ok( $m->add('/doc/review_coorporate.php?val1=this'));
ok( $m->add('/tips'));
$m->add('/cars/');
$m->menu_class_set('mainmenu');
package MTest;
use strict;
use CGI::Application::Plugin::Menu;
sub new {
my ($class) = shift;
return bless {};
}