| 1 | package Crop; | ||
| 2 | |||
| 3 | our $VERSION = '0.1.27'; | ||
| 4 | |||
| 5 | =pod | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Crop - Creazilla on Perl (Crop) Framework | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | use Crop; | ||
| 14 | my $config = Crop->C; | ||
| 15 | my $server = Crop->S; | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | Creazilla on Perl (Crop) is a Perl framework designed to make writing web scripts much easier. It hides the SQL-layer from the programmer and requires no wide experience to write top-level scripts. | ||
| 20 | |||
| 21 | Crop implements: | ||
| 22 | |||
| 23 | =over 4 | ||
| 24 | |||
| 25 | =item * Class attributes inheritance | ||
| 26 | |||
| 27 | =item * Automatic object synchronization with warehouse | ||
| 28 | |||
| 29 | =item * HTTP request routing and parameter parsing | ||
| 30 | |||
| 31 | =item * Multiple warehouses of different type at the same time | ||
| 32 | |||
| 33 | =item * Role-based access system | ||
| 34 | |||
| 35 | =back | ||
| 36 | |||
| 37 | Crop has a lightweight, simple, and clear architecture, making changes to Crop itself simple. It uses common Perl syntax, and only generates getters/setters implicitly, making debugging easy. | ||
| 38 | |||
| 39 | =head1 INSTALLATION | ||
| 40 | |||
| 41 | To install this module, run the following commands: | ||
| 42 | |||
| 43 | perl Makefile.PL | ||
| 44 | make | ||
| 45 | make test | ||
| 46 | make install | ||
| 47 | |||
| 48 | =head1 DEPENDENCIES | ||
| 49 | |||
| 50 | The following Perl modules are required to use Crop: | ||
| 51 | |||
| 52 | =over 4 | ||
| 53 | |||
| 54 | =item * XML::LibXML | ||
| 55 | |||
| 56 | =item * Time::Stamp | ||
| 57 | |||
| 58 | =item * Clone | ||
| 59 | |||
| 60 | =item * XML::LibXSLT | ||
| 61 | |||
| 62 | =item * JSON | ||
| 63 | |||
| 64 | =item * CGI::Cookie | ||
| 65 | |||
| 66 | =item * CGI::Fast | ||
| 67 | |||
| 68 | =back | ||
| 69 | |||
| 70 | =head1 METHODS | ||
| 71 | |||
| 72 | =head2 C | ||
| 73 | |||
| 74 | my $config = Crop->C; | ||
| 75 | |||
| 76 | Returns the configuration data as a hash reference. | ||
| 77 | |||
| 78 | =head2 I_can | ||
| 79 | |||
| 80 | $self->I_can(%privileges); | ||
| 81 | |||
| 82 | Checks rights. All privileges must be present in the current client rights. Returns true if OK, false otherwise. | ||
| 83 | |||
| 84 | =head2 S | ||
| 85 | |||
| 86 | my $server = Crop->S; | ||
| 87 | |||
| 88 | Accessor to the Crop::Server. Returns the server object if running, or 'Crop' otherwise. | ||
| 89 | |||
| 90 | =head1 CONTRIBUTING | ||
| 91 | |||
| 92 | To contribute to Crop, follow these steps: | ||
| 93 | |||
| 94 | =over 4 | ||
| 95 | |||
| 96 | =item 1. Fork the repository on GitHub. | ||
| 97 | |||
| 98 | =item 2. Clone your fork locally. | ||
| 99 | |||
| 100 | =item 3. Install dependencies using cpan or cpanm. | ||
| 101 | |||
| 102 | =item 4. Run tests using make test. | ||
| 103 | |||
| 104 | =item 5. Submit a pull request with your changes. | ||
| 105 | |||
| 106 | =back | ||
| 107 | |||
| 108 | =head1 CHANGELOG | ||
| 109 | |||
| 110 | See the README.md for the full changelog. | ||
| 111 | |||
| 112 | =head1 SPONSORS | ||
| 113 | |||
| 114 | Creazilla on Perl has been sponsored by L<Creazilla.com|https://creazilla.com/>. | ||
| 115 | |||
| 116 | =head1 AUTHORS | ||
| 117 | |||
| 118 | Euvgenio (Core Developer) | ||
| 119 | |||
| 120 | Alex (Contributor) | ||
| 121 | |||
| 122 | =head1 COPYRIGHT AND LICENSE | ||
| 123 | |||
| 124 | Apache 2.0 | ||
| 125 | |||
| 126 | =head1 SEE ALSO | ||
| 127 | |||
| 128 | L<https://creazilla.com/pages/creazilla-on-perl> | ||
| 129 | L<https://github.com/alextech7/crop> | ||
| 130 | |||
| 131 | =cut | ||
| 132 | |||
| 133 | use v5.14; | ||
| 134 | use warnings; | ||
| 135 | |||
| 136 | use Crop::Config; | ||
| 137 | |||
| 138 | =begin nd | ||
| 139 | Method: C ( ) | ||
| 140 | Get config data. | ||
| 141 | |||
| 142 | Returns: | ||
| 143 | A hash of configuration values: | ||
| 144 | (start code) | ||
| 145 | config = { | ||
| 146 | install => { | ||
| 147 | path => '/home/cz/back/install', | ||
| 148 | }, | ||
| 149 | warehouse => { | ||
| 150 | db => { | ||
| 151 | main => { | ||
| 152 | name => 'cz', | ||
| 153 | server => { | ||
| 154 | host => 'localhost', | ||
| 155 | port => 5432, | ||
| 156 | }, | ||
| 157 | driver => 'Pg', | ||
| 158 | role => { | ||
| 159 | admin => { | ||
| 160 | login => 'cz_admin', | ||
| 161 | pass => 'secret1', | ||
| 162 | }, | ||
| 163 | user => { | ||
| 164 | pass => 'cz_user', | ||
| 165 | login => 'secret2', | ||
| 166 | }, | ||
| 167 | }, | ||
| 168 | }, | ||
| 169 | }, | ||
| 170 | relation => { | ||
| 171 | http => 'main', | ||
| 172 | item => 'main', | ||
| 173 | }, | ||
| 174 | }, | ||
| 175 | logLevel => 'WARNING', | ||
| 176 | debug => { | ||
| 177 | layer => [ | ||
| 178 | 'APP' | ||
| 179 | ], | ||
| 180 | output => 'On' | ||
| 181 | }, | ||
| 182 | }; | ||
| 183 | (end code) | ||
| 184 | =cut | ||
| 185 | sub C { Crop::Config->data } | ||
| 186 | |||
| 187 | =begin nd | ||
| 188 | Method: I_can (%privileges) | ||
| 189 | Check Rights. | ||
| 190 | |||
| 191 | All %privileges must present in current client Rights. | ||
| 192 | |||
| 193 | Parameters: | ||
| 194 | %privileges - hash {READ => 'Crop', ...} | ||
| 195 | |||
| 196 | Returns: | ||
| 197 | true - if ok | ||
| 198 | false - otherwise | ||
| 199 | =cut | ||
| 200 | sub I_can { | ||
| 201 | my ($self, %priv) = @_; | ||
| 202 | |||
| 203 | my $server = $Crop::Server::Server; | ||
| 204 | |||
| 205 | $server->rights->ok(%priv); | ||
| 206 | } | ||
| 207 | |||
| 208 | =begin nd | ||
| 209 | Method: S () | ||
| 210 | Accessor to the <Crop::Server>. | ||
| 211 | |||
| 212 | Since an access to database by Server class is imposible if code is not running by FastCGI: | ||
| 213 | > $self->S->D | ||
| 214 | go to replace intermediate class to 'Crop' to get access by this top-level class. | ||
| 215 | |||
| 216 | Returns: | ||
| 217 | Server object - if is running | ||
| 218 | 'Crop' string - otherwise | ||
| 219 | |||
| 220 | TODO: | ||
| 221 | The D() method. | ||
| 222 | =cut | ||
| 223 | sub S { $Crop::Server::Server or 'Crop' } | ||
| 224 | |||
| 225 | 1; |