| 1 | package Tags::HTML::Login::Access; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use base qw(Tags::HTML); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use Class::Utils qw(set_params split_params); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Error::Pure qw(err); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use List::Util qw(none); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | Readonly::Array our @FORM_METHODS => qw(post get); | |||||||||
| 13 | |||||||||||
| 14 | 3 | our $VERSION = 0.02; | |||||||||
| 15 | |||||||||||
| 16 | # Constructor. | ||||||||||
| 17 | sub new { | ||||||||||
| 18 | 6 | ▶ | my ($class, @params) = @_; | ||||||||
|
Subroutine
new: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||
| 19 | |||||||||||
| 20 | # Create object. | ||||||||||
| 21 | 6 | my ($object_params_ar, $other_params_ar) = split_params( | |||||||||
| 22 | ['css_access', 'form_method', 'lang', 'register_url', 'text', 'width'], @params); | ||||||||||
| 23 | 6 | my $self = $class->SUPER::new(@{$other_params_ar}); | |||||||||
| 24 | |||||||||||
| 25 | # CSS style for access box. | ||||||||||
| 26 | 3 | $self->{'css_access'} = 'form-login'; | |||||||||
| 27 | |||||||||||
| 28 | # Form method. | ||||||||||
| 29 | 3 | $self->{'form_method'} = 'post'; | |||||||||
| 30 | |||||||||||
| 31 | # Language. | ||||||||||
| 32 | 3 | $self->{'lang'} = 'eng'; | |||||||||
| 33 | |||||||||||
| 34 | # Register URL. | ||||||||||
| 35 | 3 | $self->{'register_url'} = undef; | |||||||||
| 36 | |||||||||||
| 37 | # Language texts. | ||||||||||
| 38 | 3 | $self->{'text'} = { | |||||||||
| 39 | 'eng' => { | ||||||||||
| 40 | 'login' => 'Login', | ||||||||||
| 41 | 'password_label' => 'Password', | ||||||||||
| 42 | 'username_label' => 'User name', | ||||||||||
| 43 | 'submit' => 'Login', | ||||||||||
| 44 | 'register' => 'Register', | ||||||||||
| 45 | }, | ||||||||||
| 46 | }; | ||||||||||
| 47 | |||||||||||
| 48 | # Login box width. | ||||||||||
| 49 | 3 | $self->{'width'} = '300px'; | |||||||||
| 50 | |||||||||||
| 51 | # Process params. | ||||||||||
| 52 | 3 | set_params($self, @{$object_params_ar}); | |||||||||
| 53 | |||||||||||
| 54 | # Check form method. | ||||||||||
| 55 | 3 | ▶ | if (none { $self->{'form_method'} eq $_ } @FORM_METHODS) { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||
| 56 | 0 | err "Parameter 'form_method' has bad value."; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | # TODO Check lang. | ||||||||||
| 60 | |||||||||||
| 61 | # Check text for lang | ||||||||||
| 62 | 3 | ▶ | if (! defined $self->{'text'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | err "Parameter 'text' is required."; | |||||||||
| 64 | } | ||||||||||
| 65 | 3 | ▶ | if (ref $self->{'text'} ne 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | err "Parameter 'text' must be a hash with language texts."; | |||||||||
| 67 | } | ||||||||||
| 68 | 3 | ▶ | if (! exists $self->{'text'}->{$self->{'lang'}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | err "Texts for language '$self->{'lang'}' doesn't exist."; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | # Object. | ||||||||||
| 73 | 3 | return $self; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | # Process 'Tags'. | ||||||||||
| 77 | sub _process { | ||||||||||
| 78 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_process: not called CC=2 SCAR=17.9
| |||||||||||
| 79 | |||||||||||
| 80 | 0 | my $username_id = 'username'; | |||||||||
| 81 | 0 | my $password_id = 'password'; | |||||||||
| 82 | |||||||||||
| 83 | # Main content. | ||||||||||
| 84 | $self->{'tags'}->put( | ||||||||||
| 85 | ['b', 'form'], | ||||||||||
| 86 | ['a', 'class', $self->{'css_access'}], | ||||||||||
| 87 | ['a', 'method', $self->{'form_method'}], | ||||||||||
| 88 | |||||||||||
| 89 | ['b', 'fieldset'], | ||||||||||
| 90 | ['b', 'legend'], | ||||||||||
| 91 | ['d', $self->_text('login')], | ||||||||||
| 92 | ['e', 'legend'], | ||||||||||
| 93 | |||||||||||
| 94 | ['b', 'p'], | ||||||||||
| 95 | ['b', 'label'], | ||||||||||
| 96 | ['a', 'for', $username_id], | ||||||||||
| 97 | ['e', 'label'], | ||||||||||
| 98 | ['d', $self->_text('username_label')], | ||||||||||
| 99 | ['b', 'input'], | ||||||||||
| 100 | ['a', 'type', 'text'], | ||||||||||
| 101 | ['a', 'name', $username_id], | ||||||||||
| 102 | ['a', 'id', $username_id], | ||||||||||
| 103 | ['e', 'input'], | ||||||||||
| 104 | ['e', 'p'], | ||||||||||
| 105 | |||||||||||
| 106 | ['b', 'p'], | ||||||||||
| 107 | ['b', 'label'], | ||||||||||
| 108 | ['a', 'for', $password_id], | ||||||||||
| 109 | ['d', $self->_text('password_label')], | ||||||||||
| 110 | ['e', 'label'], | ||||||||||
| 111 | ['b', 'input'], | ||||||||||
| 112 | ['a', 'type', 'password'], | ||||||||||
| 113 | ['a', 'name', $password_id], | ||||||||||
| 114 | ['a', 'id', $password_id], | ||||||||||
| 115 | ['e', 'input'], | ||||||||||
| 116 | ['e', 'p'], | ||||||||||
| 117 | |||||||||||
| 118 | ['b', 'p'], | ||||||||||
| 119 | ['b', 'button'], | ||||||||||
| 120 | ['a', 'type', 'submit'], | ||||||||||
| 121 | ['a', 'name', 'login'], | ||||||||||
| 122 | ['a', 'value', 'login'], | ||||||||||
| 123 | ['d', $self->_text('submit')], | ||||||||||
| 124 | ['e', 'button'], | ||||||||||
| 125 | ['e', 'p'], | ||||||||||
| 126 | |||||||||||
| 127 | defined $self->{'register_url'} ? ( | ||||||||||
| 128 | ['b', 'a'], | ||||||||||
| 129 | 0 | ▶ | ['a', 'href', $self->{'register_url'}], | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | ['d', $self->_text('register')], | ||||||||||
| 131 | ['e', 'a'], | ||||||||||
| 132 | ) : (), | ||||||||||
| 133 | |||||||||||
| 134 | ['e', 'fieldset'], | ||||||||||
| 135 | |||||||||||
| 136 | ['e', 'form'], | ||||||||||
| 137 | ); | ||||||||||
| 138 | |||||||||||
| 139 | 0 | return; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | # Process 'CSS::Struct'. | ||||||||||
| 143 | sub _process_css { | ||||||||||
| 144 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_process_css: not called CC=1 SCAR=6.9
| |||||||||||
| 145 | |||||||||||
| 146 | $self->{'css'}->put( | ||||||||||
| 147 | ['s', '.'.$self->{'css_access'}], | ||||||||||
| 148 | ['d', 'width', $self->{'width'}], | ||||||||||
| 149 | ['d', 'background-color', '#f2f2f2'], | ||||||||||
| 150 | ['d', 'padding', '20px'], | ||||||||||
| 151 | ['d', 'border-radius', '5px'], | ||||||||||
| 152 | ['d', 'box-shadow', '0 0 10px rgba(0, 0, 0, 0.2)'], | ||||||||||
| 153 | ['e'], | ||||||||||
| 154 | |||||||||||
| 155 | ['s', '.'.$self->{'css_access'}.' fieldset'], | ||||||||||
| 156 | ['d', 'border', 'none'], | ||||||||||
| 157 | ['d', 'padding', 0], | ||||||||||
| 158 | ['d', 'margin-bottom', '20px'], | ||||||||||
| 159 | ['e'], | ||||||||||
| 160 | |||||||||||
| 161 | ['s', '.'.$self->{'css_access'}.' legend'], | ||||||||||
| 162 | ['d', 'font-weight', 'bold'], | ||||||||||
| 163 | ['d', 'margin-bottom', '10px'], | ||||||||||
| 164 | ['e'], | ||||||||||
| 165 | |||||||||||
| 166 | ['s', '.'.$self->{'css_access'}.' p'], | ||||||||||
| 167 | ['d', 'margin', 0], | ||||||||||
| 168 | ['d', 'padding', '10px 0'], | ||||||||||
| 169 | ['e'], | ||||||||||
| 170 | |||||||||||
| 171 | ['s', '.'.$self->{'css_access'}.' label'], | ||||||||||
| 172 | ['d', 'display', 'block'], | ||||||||||
| 173 | ['d', 'font-weight', 'bold'], | ||||||||||
| 174 | ['d', 'margin-bottom', '5px'], | ||||||||||
| 175 | ['e'], | ||||||||||
| 176 | |||||||||||
| 177 | ['s', '.'.$self->{'css_access'}.' input[type="text"]'], | ||||||||||
| 178 | ['s', '.'.$self->{'css_access'}.' input[type="password"]'], | ||||||||||
| 179 | ['d', 'width', '100%'], | ||||||||||
| 180 | ['d', 'padding', '8px'], | ||||||||||
| 181 | ['d', 'border', '1px solid #ccc'], | ||||||||||
| 182 | ['d', 'border-radius', '3px'], | ||||||||||
| 183 | ['e'], | ||||||||||
| 184 | |||||||||||
| 185 | ['s', '.'.$self->{'css_access'}.' button[type="submit"]'], | ||||||||||
| 186 | ['d', 'width', '100%'], | ||||||||||
| 187 | ['d', 'padding', '10px'], | ||||||||||
| 188 | ['d', 'background-color', '#4CAF50'], | ||||||||||
| 189 | ['d', 'color', '#fff'], | ||||||||||
| 190 | ['d', 'border', 'none'], | ||||||||||
| 191 | ['d', 'border-radius', '3px'], | ||||||||||
| 192 | ['d', 'cursor', 'pointer'], | ||||||||||
| 193 | ['e'], | ||||||||||
| 194 | |||||||||||
| 195 | 0 | ['s', '.'.$self->{'css_access'}.' button[type="submit"]:hover'], | |||||||||
| 196 | ['d', 'background-color', '#45a049'], | ||||||||||
| 197 | ['e'], | ||||||||||
| 198 | ); | ||||||||||
| 199 | |||||||||||
| 200 | 0 | return; | |||||||||
| 201 | } | ||||||||||
| 202 | |||||||||||
| 203 | sub _text { | ||||||||||
| 204 | 0 | ▶ | my ($self, $key) = @_; | ||||||||
|
Subroutine
_text: not called CC=2 SCAR=17.9
| |||||||||||
| 205 | |||||||||||
| 206 | 0 | ▶ | if (! exists $self->{'text'}->{$self->{'lang'}}->{$key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 207 | 0 | err "Text for lang '$self->{'lang'}' and key '$key' doesn't exist."; | |||||||||
| 208 | } | ||||||||||
| 209 | |||||||||||
| 210 | 0 | return $self->{'text'}->{$self->{'lang'}}->{$key}; | |||||||||
| 211 | } | ||||||||||
| 212 | |||||||||||
| 213 | 3 | 1; | |||||||||
| 214 | |||||||||||
| 215 | __END__ | ||||||||||