Portal.pm

filter: Statementstmt 38.3% 23 / 60 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 33.3% 31 / 93 CC 11 SCAR 44.0
CC
11
Cov
29%
activate
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 81.1
↑ Summary Portal/Controls/register.pm »
1 package CGI::Portal;
2 # Copyright (c) 2008 Alexander David P. All rights reserved.
3 #
4 # Create, run requested object and print
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use CGI::Portal::RDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use CGI::Portal::Scripts::Header;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use CGI::Portal::Scripts::Footer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 $VERSION = "0.12";
17  
18 1 1;
19  
20 # Create, run requested object and print
21 0 ▶sub activate {
Subroutine activate: not called CC=11 SCAR=48.8
Pod documented
22 0 my $conf = shift;
23 0 my $e;
24 my $cl;
25  
26 0 my $cgi = new CGI();
27  
28 # Get parameters
29 0 my @v = $cgi->param;
30 0 my %in;
31 0 foreach my $f (@v){
32 0 my $v = $cgi->param($f);
33 0 $v =~ s/<.*\r*\n*.*>//g;
34 0 $in{$f} = $v;
35 }
36  
37 # Get a database handle
38 0 my $rdb = CGI::Portal::RDB->new("DBI:$conf->{'database_type'}:database=$conf->{'database_name'};host=$conf->{'database_host'};", $conf->{'database_user'}, $conf->{'database_passw'});
39  
40 # Reference to parameters, database handle, config
41 0 my $i = {'in', \%in,
42 'rdb', $rdb,
43 'conf', $conf};
44  
45 # Get requested action or default
46 0 my $c = $conf->{'actions'}[0];
47 0 foreach my $a (@{$conf->{'actions'}}) {
48 0 ▶ if ($in{'action'} eq $a) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in{"action"} eq $a) 0 0 0
49 0 $c = $a;
50 }
51 }
52  
53 # Use a control
54 0 ▶ if ($in{'submit'} || $in{'Submit'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in{"submit"} or $in{"Submit"}) 0 0 0
Condition0%0/3
$in{"submit"} or $in{"Submit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$in{"submit"} or $in{"Submit"}
$in{"submit"} $in{"Submit"}
Truth table0%0/3
A or B
A= $in{"submit"}B= $in{"Submit"}
ABresult
1X1
011
000
55 0 $cl = "CGI::Portal::Controls::$c";
56 0 eval "use $cl;";
57 }
58 # Use a script
59 0 ▶ if ($@ || ! ($in{'submit'} || $in{'Submit'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $in{"submit"} || $in{"Submit"}) 0 0 0
Condition0%0/6
$@ or not $in{"submit"} || $in{"Submit"}
l!l&&r!l&&!r
000
$in{'submit'} || $in{'Submit'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$@ or not $in{"submit"} || $in{"Submit"}
$@ $in{'submit'} $in{'Submit'}
Truth table0%0/4
A or not(B || C)
A= $@B= $in{'submit'}C= $in{'Submit'}
ABCresult
1XX1
0001
01X0
0010
60 0 $cl = "CGI::Portal::Scripts::$c";
61 0 eval "use $cl;";
62 }
63  
64 # Use default
65 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
66 0 $cl = "CGI::Portal::Scripts::$conf->{'actions'}[0]";
67 0 eval "use $cl;";
68 }
69 # Create an object and run launch
70 0 ▶ if (! $@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
71 0 $e = $cl->new($i);
72 0 $e->launch;
73 }
74  
75 # Create header object and run launch
76 0 my $header = CGI::Portal::Scripts::Header->new({
77 'in', \%in,
78 'rdb', $rdb,
79 'conf', $conf});
80 0 $header->launch($e);
81  
82 # Create footer object and run launch
83 0 my $footer = CGI::Portal::Scripts::Footer->new({
84 'in', \%in,
85 'rdb', $rdb,
86 'conf', $conf});
87 0 $footer->launch($e);
88  
89 # Print
90 0 print $e->{'cookies'};
91 0 print $cgi->header;
92 0 print $header->{'out'};
93 0 print $e->{'out'};
94 0 print $footer->{'out'};
95 }
96  
97 =head1 NAME
98  
99 CGI::Portal - MVC Framework for Multiuser Applications
100  
101 =head1 SYNOPSIS
102  
103 use CGI::Portal;
104  
105 CGI::Portal::activate({'database_type' => "mysql",
106  
107 'database_name' => "some_name",
108 'database_host' => "localhost",
109 'database_user' => "some_user",
110 'database_passw' => "some_password",
111  
112 'user_table' => "users",
113 'user_index_field' => "id",
114 'user_user_field' => "user",
115 'user_passw_field' => "passw",
116 'user_additional' => ["email","first_name","middle_initial","last_name","city","state","country"],
117 # at least: ["email"],
118  
119 'session_table' => "sessions",
120 'session_index_field' => "id",
121 'session_sid_field' => "sid",
122 'session_user_field' => "user",
123 'session_start_field' => "session_start",
124 'session_additional' => "",
125  
126  
127 # Accessible classes, the first is the default action
128  
129 'actions' => ["logon", "logoff", "register", "profile", "changepw", "emailpw"],
130  
131 'session_length' => 7200,
132 'admin_email' => "some_user\@some_host.com",
133  
134 'template_dir' => "templates/", # include trailing slash
135 'header_html' => "header.html",
136 'footer_html' => "footer.html",
137 'logon_success_html' => "logon.html"});
138  
139 =head1 DESCRIPTION
140  
141 CGI::Portal is a MVC framework for the design of extensible,
142 plug-configure-and-play multiuser web applications based on preferred object
143 oriented coding standards. It provides authentication, session management, internal
144 redirects and a modular architecture to build complex applications.
145  
146 It requires a database including a user and a sessions table, a collection of HTML::Template
147 style templates and a properly configured startup script. To start with CGI::Portal you
148 may want to install the provided templates at http://cgi-portal.sourceforge.net/
149  
150 All requests access through the startup script, and are handled by the class in
151 the CGI::Portal::Scripts and CGI::Portal::Controls namespace that corresponds to the desired action.
152  
153 portal.cgi?action=foo calls CGI::Portal::Scripts::foo::launch()
154  
155 portal.cgi?action=foo&Submit=1 calls CGI::Portal::Controls::foo::launch()
156  
157 =head1 FUNCTIONS
158  
159 =head2 activate
160  
161 CGI::Portal::activate($conf) takes a reference to the configuration hash, collects
162 input parameters, creates a database object, and passes those on to your class
163 for creating an object instance. It then runs your classes "launch" method and
164 concludes by doing the printing for you. This function is called once from your
165 startup script.
166  
167 =head1 BUILDING APPLICATIONS
168  
169 See CGI::Portal::Scripts on Building Applications
170  
171 =head1 INSTALLATION
172  
173 perl Makefile.PL
174 make
175 make test
176 make install
177  
178 =head1 AUTHOR
179  
180 Alexander David P <cpanalpo@yahoo.com>
181  
182 =cut
↑ Summary Portal/Controls/register.pm »