Portal/Login.pm

filter: Statementstmt 11.2% 9 / 80 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 22.2% 2 / 9 Podpod 0.0% 0 / 4 totaltotal 9.4% 11 / 117 CC 15 SCAR 44.3
CC
15
Cov
9%
cmd
156.0
update
12.0
init_user
6.0
CRAP 83.9
« Portal/Top.pm ↑ Summary Portal.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package NetServer::Portal::Login;
3 1 ▶use NetServer::Portal qw($Host %PortInfo term);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 NetServer::Portal->register(cmd => "menu",
6 title => "Main Menu",
7 package => __PACKAGE__);
8  
9 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
10 0 bless { error => '' }
11 }
12  
13 0 ▶sub update {
Subroutine update: not called CC=3 SCAR=24.8
Pod undocumented
14 0 my ($o, $c) = @_;
15 0 ▶ if (!$o->{user}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o->{'user'}) { } 0 0 0
16 0 my $s = "$o->{error}\n\n\n[$Host] $0 #$$\n\nlogin: ";
17 0 $o->{error} = '';
18 0 $s;
19 } else {
20 0 my $conf = $c->conf;
21 0 my $l = $c->format_line;
22 0 my $s = NetServer::Portal::term->Tputs('cl',1,$c->{io}->fd);
23 0 $s .= $l->("NetServer::Portal v$NetServer::Portal::VERSION");
24 0 $s .= "\n";
25 0 $s .= $l->("HOST: $Host");
26 0 $s .= $l->("PID: $$");
27 0 $s .= $l->("USER: $o->{user}");
28 0 $s .= "\n\n";
29  
30 0 my @p = values %PortInfo;
31 0 @p = sort { $a->{title} cmp $b->{title} } @p;
32 0 my $fmt = " %-10s %-40s";
33 0 for my $p (@p) {
34 0 $s .= $l->($fmt, '!'.$p->{cmd}, $p->{title});
35 }
36 0 $s .= $l->($fmt, '!exit', 'End Session');
37  
38 0 $s .= "\n";
39 0 $s .= $l->($fmt, "dim r,c", "Change screen dimensions from [$conf->{rows},$conf->{cols}]");
40  
41 0 $s .= "\n" x ($conf->{rows} - 13 - @p);
42 0 $s .= $l->($o->{error});
43 0 $s .= "% ";
44 0 $s;
45 }
46 }
47  
48 0 ▶sub init_user {
Subroutine init_user: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my ($o, $cl, $id) = @_;
50 0 $o->{user} = $id;
51 0 my $t = $NetServer::Portal::StoreTop;
52 0 ▶ if (! exists $t->{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $t->{$id}) { } 0 0 0
53 0 my $u = $t->{$id} = {};
54 0 $u->{rows} = 24;
55 0 $u->{cols} = 80;
56 0 $u->{screen} = __PACKAGE__;
57 } else {
58 0 eval { $cl->set_screen($t->{$id}{screen}) }; # failure OK
59 }
60 }
61  
62 0 ▶sub cmd {
Subroutine cmd: not called CC=12 SCAR=50.5
Pod undocumented
63 0 my ($o, $cl, $in) = @_;
64 0 ▶ if (!$o->{user}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o->{'user'}) { } 0 0 0
65 0 ▶ if ($in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in) 0 0 0
66 0 ▶ if ($in =~ m/^[a-zA-Z\d]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in =~ /^[a-zA-Z\d]+$/) { } 0 0 0
67 # optional password protection XXX
68 0 $o->init_user($cl, $in);
69 } else {
70 0 $o->{error} = "'$in' is not a valid login";
71 }
72 }
73 } else {
74 0 ▶ if (!$in) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in) 0 0 0
75 0 $o->{error} = '';
76 0 return;
77 }
78 0 ▶ if ($in =~ m/^dim \s* (\d+) (\s*,\s*|\s+) (\d+)$/x) {
Branch: 3 branches
BranchTrueFalseTotal
if ($in =~ /^dim \s* (\d+) (\s*,\s*|\s+) (\d+)$/x) { } 0 0 0
elsif ($in eq '!exit') { } 0 0 0
elsif ($in eq '!back') { } 0 0 0
79 0 my ($r,$c) = ($1,$3);
80 0 ▶ $r = 12 if $r < 12;
Branch: 1 branch
BranchTrueFalseTotal
if $r < 12 0 0 0
81 0 ▶ $c = 70 if $c < 70;
Branch: 1 branch
BranchTrueFalseTotal
if $c < 70 0 0 0
82 0 my $conf = $cl->conf;
83 0 $conf->{rows} = $r;
84 0 $conf->{cols} = $c;
85 } elsif ($in eq '!exit') {
86 0 $cl->cancel;
87 } elsif ($in eq '!back') {
88 0 $cl->set_screen('back');
89 } else {
90 0 for my $p (values %PortInfo) {
91 0 ▶ if ($in eq '!'.$p->{cmd}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in eq '!' . $p->{"cmd"}) 0 0 0
92 0 $cl->set_screen($p->{package});
93 0 return;
94 }
95 }
96 0 $o->{error} = "What is '$in'?";
97 }
98 }
99 }
100  
101 package NetServer::Portal::About;
102  
103 1 NetServer::Portal->register(cmd => "about",
104 title => "About This Extension",
105 package => __PACKAGE__);
106  
107 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
108  
109 0 ▶sub cmd {
Subroutine cmd: not called CC=1 SCAR=6.9
110 0 my ($o, $cl) = @_;
111 0 $cl->set_screen('back');
112 }
113  
114 0 ▶sub update {
Subroutine update: not called CC=1 SCAR=6.9
115 0 my ($o, $c) = @_;
116 0 my $ln = $c->format_line;
117 0 my $s = "NetServer::Portal v$NetServer::Portal::VERSION\n\n";
118 0 $s .= 'Copyright © 2000 Joshua Nathaniel Pritikin. All rights reserved.
119 This program is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.';
121 0 $s .= "\n" x 3;
122 0 $s .= q[Send questions about this extension to perl-loop@perl.org.
123 If you wish to subscribe to this mailing list, send email to:
124  
125 majordomo@perl.org
126  
127 The body of your message should read:
128  
129 subscribe perl-loop
130  
131  
132 If you are curious about the author's motivation, see:
133 http://why-compete.org
134  
135  
136 Enjoy! ];
137 0 $s;
138 }
139  
140 1 1;
« Portal/Top.pm ↑ Summary Portal.pm »