Permalink
Browse files

removed unused features from Mojo::Base and simplified api

  • Loading branch information...
1 parent 0d7ccf2 commit 58599d0153c9c0eec88cb1563f9c0e3f43d46010 Sebastian Riedel committed Aug 11, 2009
Showing with 160 additions and 210 deletions.
  1. +5 −0 Changes
  2. +3 −4 lib/Mojo.pm
  3. +13 −51 lib/Mojo/Base.pm
  4. +1 −1 lib/Mojo/Buffer.pm
  5. +2 −2 lib/Mojo/Client.pm
  6. +4 −5 lib/Mojo/Content.pm
  7. +1 −1 lib/Mojo/Content/MultiPart.pm
  8. +1 −2 lib/Mojo/File.pm
  9. +1 −1 lib/Mojo/File/Memory.pm
  10. +3 −3 lib/Mojo/Filter.pm
  11. +1 −1 lib/Mojo/Headers.pm
  12. +1 −1 lib/Mojo/Home.pm
  13. +2 −3 lib/Mojo/Log.pm
  14. +3 −3 lib/Mojo/Message.pm
  15. +2 −2 lib/Mojo/Message/Request.pm
  16. +1 −1 lib/Mojo/Message/Response.pm
  17. +2 −2 lib/Mojo/Parameters.pm
  18. +2 −2 lib/Mojo/Path.pm
  19. +1 −1 lib/Mojo/Pipeline.pm
  20. +4 −4 lib/Mojo/Script.pm
  21. +2 −2 lib/Mojo/Script/Cgi.pm
  22. +2 −2 lib/Mojo/Script/Daemon.pm
  23. +2 −2 lib/Mojo/Script/DaemonPrefork.pm
  24. +2 −2 lib/Mojo/Script/Fastcgi.pm
  25. +5 −6 lib/Mojo/Script/Generate.pm
  26. +2 −2 lib/Mojo/Script/Generate/App.pm
  27. +2 −2 lib/Mojo/Script/Generate/Makefile.pm
  28. +2 −2 lib/Mojo/Script/Test.pm
  29. +3 −3 lib/Mojo/Scripts.pm
  30. +5 −10 lib/Mojo/Server.pm
  31. +1 −1 lib/Mojo/Server/CGI.pm
  32. +5 −5 lib/Mojo/Server/Daemon.pm
  33. +7 −8 lib/Mojo/Server/Daemon/Prefork.pm
  34. +1 −1 lib/Mojo/Stateful.pm
  35. +10 −10 lib/Mojo/Template.pm
  36. +2 −3 lib/Mojo/Template/Exception.pm
  37. +3 −3 lib/Mojo/Transaction.pm
  38. +1 −1 lib/Mojo/URL.pm
  39. +2 −2 lib/Mojo/Upload.pm
  40. +2 −2 lib/MojoX/Dispatcher/Routes.pm
  41. +1 −2 lib/MojoX/Dispatcher/Routes/Controller.pm
  42. +1 −1 lib/MojoX/Dispatcher/Static.pm
  43. +4 −4 lib/MojoX/Renderer.pm
  44. +3 −3 lib/MojoX/Routes.pm
  45. +3 −3 lib/MojoX/Routes/Match.pm
  46. +9 −9 lib/MojoX/Routes/Pattern.pm
  47. +1 −2 lib/MojoX/Types.pm
  48. +6 −8 lib/Mojolicious.pm
  49. +1 −2 lib/Mojolicious/Script/Generate.pm
  50. +2 −2 lib/Mojolicious/Script/Generate/App.pm
  51. +2 −2 lib/Mojolicious/Script/Generate/LiteApp.pm
  52. +2 −2 lib/Mojolicious/Script/Routes.pm
  53. +2 −2 lib/Mojolicious/Scripts.pm
  54. +3 −3 lib/Test/Mojo/Server.pm
  55. +6 −6 t/mojo/base.t
View
@@ -1,6 +1,11 @@
This file documents the revision history for Perl extension Mojo.
0.991247 2009-08-01 00:00:00
+ - Removed unused features from Mojo::Base and simplified API, this
+ change is not backwards compatible!
+ __PACKAGE__->attr('foo', default => 'bar');
+ becomes
+ __PACKAGE__->attr(foo => 'bar');
- Merged eplite and epl, this change is not backwards compatible, you
will have to rename all your eplite templates to epl.
- Simplified MojoX::Renderer, this change is not backwards
View
@@ -14,17 +14,16 @@ use Mojo::Scripts;
use Mojo::Transaction;
__PACKAGE__->attr(
- 'build_tx_cb',
- default => sub {
+ build_tx_cb => sub {
sub {
my $tx = Mojo::Transaction->new;
$tx->res->headers->header('X-Powered-By' => 'Mojo (Perl)');
return $tx;
}
}
);
-__PACKAGE__->attr('home', default => sub { Mojo::Home->new });
-__PACKAGE__->attr('log', default => sub { Mojo::Log->new });
+__PACKAGE__->attr(home => sub { Mojo::Home->new });
+__PACKAGE__->attr(log => sub { Mojo::Log->new });
# Oh, so they have internet on computers now!
our $VERSION = '0.991247';
View
@@ -23,20 +23,11 @@ sub new {
# so we optimize them by compiling our own code, don't be scared, we have
# tests for every single case
sub attr {
- my $class = shift;
- my $attrs = shift;
+ my ($class, $attrs, $default) = @_;
# Shortcut
return unless $class && $attrs;
- # Check arguments
- my $args = exists $_[1] ? {@_} : ($_[0] || {});
-
- my $chained = exists $args->{chained} ? delete $args->{chained} : 1;
- my $default = delete $args->{default};
-
- undef $args;
-
# Check default
Carp::croak('Default has to be a code reference or constant value')
if ref $default && ref $default ne 'CODE';
@@ -49,7 +40,7 @@ sub attr {
my $ws = ' ';
for my $attr (@$attrs) {
- Carp::croak("Attribute '$attr' invalid")
+ Carp::croak(qq/Attribute "$attr" invalid/)
unless $attr =~ /^[a-zA-Z_]\w*$/;
# Header
@@ -78,22 +69,11 @@ sub attr {
}
$code .= "$ws}\n";
- # Store argument optimized
- unless ($chained) {
- $code .= "${ws}return \$_[0]->{'$attr'} = \$_[1];\n";
- }
-
- # Store argument the old way
- else {
- $code .= "$ws\$_[0]->{'$attr'} = \$_[1];\n";
- }
+ # Store value
+ $code .= "$ws\$_[0]->{'$attr'} = \$_[1];\n";
- # Return value or instance for chained
- if ($chained) {
- $code .= "${ws}return ";
- $code .= $chained ? '$_[0]' : "\$_[0]->{'$attr'}";
- $code .= ";\n";
- }
+ # Return invocant
+ $code .= "${ws}return \$_[0];\n";
# Footer
$code .= '};';
@@ -125,11 +105,8 @@ Mojo::Base - Minimal Base Class For Mojo Projects
use base 'Mojo::Base';
__PACKAGE__->attr('driver');
- __PACKAGE__->attr('doors', default => 2);
- __PACKAGE__->attr([qw/passengers seats/],
- chained => 0,
- default => sub { 2 }
- );
+ __PACKAGE__->attr('doors' => 2);
+ __PACKAGE__->attr([qw/passengers seats/] => sub { 2 });
package main;
use Car;
@@ -139,12 +116,11 @@ Mojo::Base - Minimal Base Class For Mojo Projects
print $bmw->doors(5)->doors;
my $mercedes = Car->new(driver => 'Sebastian');
- print $mercedes->passengers(7);
+ print $mercedes->passengers(7)->passengers;
=head1 DESCRIPTION
L<Mojo::Base> is a minimalistic base class for L<Mojo> projects.
-For debugging you can set the C<MOJO_BASE_DEBUG> environment variable.
=head1 METHODS
@@ -158,23 +134,9 @@ For debugging you can set the C<MOJO_BASE_DEBUG> environment variable.
__PACKAGE__->attr('name');
__PACKAGE__->attr([qw/name1 name2 name3/]);
- __PACKAGE__->attr('name', chained => 0, default => 'foo');
- __PACKAGE__->attr(name => (chained => 0, default => 'foo'));
- __PACKAGE__->attr('name', {chained => 0, default => 'foo'});
- __PACKAGE__->attr([qw/name1 name2 name3/] => {
- chained => 0,
- default => 'foo'}
- );
-
-Currently there are two options supported.
-
- chained: Whenever you call an attribute with arguments the instance
- is returned instead of the value. (This will be activated by
- default and can be deactivated by setting chained to false)
- default: Default value for the attribute, can be a coderef or constant
- value. (Not a normal reference!)
- Note that the default value is "lazy", which means it only
- gets assigned to the instance when the attribute has been
- called.
+ __PACKAGE__->attr(name => 'foo');
+ __PACKAGE__->attr(name => sub { ... });
+ __PACKAGE__->attr([qw/name1 name2 name3/] => 'foo');
+ __PACKAGE__->attr([qw/name1 name2 name3/] => sub { ... });
=cut
View
@@ -9,7 +9,7 @@ use base 'Mojo::Base';
use overload '""' => sub { shift->to_string }, fallback => 1;
use bytes;
-__PACKAGE__->attr('raw_length', default => 0);
+__PACKAGE__->attr(raw_length => 0);
sub add_chunk {
my ($self, $chunk) = @_;
View
@@ -15,8 +15,8 @@ use Socket;
use constant CHUNK_SIZE => $ENV{MOJO_CHUNK_SIZE} || 4096;
-__PACKAGE__->attr('continue_timeout', default => 5);
-__PACKAGE__->attr('keep_alive_timeout', default => 15);
+__PACKAGE__->attr(continue_timeout => 5);
+__PACKAGE__->attr(keep_alive_timeout => 15);
sub connect {
my ($self, $tx) = @_;
View
@@ -18,12 +18,11 @@ use Mojo::Headers;
use constant CHUNK_SIZE => $ENV{MOJO_CHUNK_SIZE} || 4096;
use constant MAX_MEMORY_SIZE => $ENV{MOJO_MAX_MEMORY_SIZE} || 10240;
-__PACKAGE__->attr([qw/buffer filter_buffer/],
- default => sub { Mojo::Buffer->new });
+__PACKAGE__->attr([qw/buffer filter_buffer/] => sub { Mojo::Buffer->new });
__PACKAGE__->attr([qw/body_cb filter progress_cb/]);
-__PACKAGE__->attr('file', default => sub { Mojo::File::Memory->new });
-__PACKAGE__->attr('headers', default => sub { Mojo::Headers->new });
-__PACKAGE__->attr([qw/raw_header_length relaxed/], default => 0);
+__PACKAGE__->attr(file => sub { Mojo::File::Memory->new });
+__PACKAGE__->attr(headers => sub { Mojo::Headers->new });
+__PACKAGE__->attr([qw/raw_header_length relaxed/] => 0);
sub build_body {
my $self = shift;
@@ -11,7 +11,7 @@ use bytes;
use Mojo::ByteStream 'b';
use Mojo::File;
-__PACKAGE__->attr('parts', default => sub { [] });
+__PACKAGE__->attr(parts => sub { [] });
sub body_contains {
my ($self, $chunk) = @_;
View
@@ -21,8 +21,7 @@ use constant TMPDIR => $ENV{MOJO_TMPDIR} || File::Spec->tmpdir;
__PACKAGE__->attr([qw/cleanup path/]);
__PACKAGE__->attr(
- 'handle',
- default => sub {
+ handle => sub {
my $self = shift;
my $handle = IO::File->new;
View
@@ -13,7 +13,7 @@ use IO::File;
use constant CHUNK_SIZE => $ENV{MOJO_CHUNK_SIZE} || 4096;
-__PACKAGE__->attr('content', default => sub {''});
+__PACKAGE__->attr(content => sub {''});
# There's your giraffe, little girl.
# I'm a boy.
View
@@ -11,9 +11,9 @@ use Carp 'croak';
use Mojo::Buffer;
use Mojo::Headers;
-__PACKAGE__->attr('headers', default => sub { Mojo::Headers->new });
-__PACKAGE__->attr([qw/input_buffer output_buffer/],
- default => sub { Mojo::Buffer->new });
+__PACKAGE__->attr(headers => sub { Mojo::Headers->new });
+__PACKAGE__->attr(
+ [qw/input_buffer output_buffer/] => sub { Mojo::Buffer->new });
# Quick Smithers. Bring the mind eraser device!
# You mean the revolver, sir?
View
@@ -10,7 +10,7 @@ use overload '""' => sub { shift->to_string }, fallback => 1;
use Mojo::Buffer;
-__PACKAGE__->attr('buffer', default => sub { Mojo::Buffer->new });
+__PACKAGE__->attr(buffer => sub { Mojo::Buffer->new });
my @GENERAL_HEADERS = qw/
Cache-Control
View
@@ -13,7 +13,7 @@ use FindBin;
use Mojo::Loader;
use Mojo::Script;
-__PACKAGE__->attr('app_class', default => 'Mojo::HelloWorld');
+__PACKAGE__->attr(app_class => 'Mojo::HelloWorld');
# I'm normally not a praying man, but if you're up there,
# please save me Superman.
View
@@ -11,8 +11,7 @@ use Carp 'croak';
use IO::File;
__PACKAGE__->attr(
- 'handle',
- default => sub {
+ handle => sub {
my $self = shift;
# Need a log file
@@ -25,7 +24,7 @@ __PACKAGE__->attr(
return $file;
}
);
-__PACKAGE__->attr('level', default => 'debug');
+__PACKAGE__->attr(level => 'debug');
__PACKAGE__->attr('path');
my $LEVEL = {debug => 1, info => 2, warn => 3, error => 4, fatal => 5};
View
@@ -18,9 +18,9 @@ use Mojo::Upload;
use constant CHUNK_SIZE => $ENV{MOJO_CHUNK_SIZE} || 4096;
-__PACKAGE__->attr('buffer', default => sub { Mojo::Buffer->new });
-__PACKAGE__->attr('content', default => sub { Mojo::Content->new });
-__PACKAGE__->attr([qw/major_version minor_version/], default => 1);
+__PACKAGE__->attr(buffer => sub { Mojo::Buffer->new });
+__PACKAGE__->attr(content => sub { Mojo::Content->new });
+__PACKAGE__->attr([qw/major_version minor_version/] => 1);
# I'll keep it short and sweet. Family. Religion. Friendship.
# These are the three demons you must slay if you wish to succeed in
@@ -10,8 +10,8 @@ use base 'Mojo::Message';
use Mojo::Cookie::Request;
use Mojo::Parameters;
-__PACKAGE__->attr('method', default => 'GET');
-__PACKAGE__->attr('url', default => sub { Mojo::URL->new });
+__PACKAGE__->attr(method => 'GET');
+__PACKAGE__->attr(url => sub { Mojo::URL->new });
sub cookies {
my $self = shift;
@@ -10,7 +10,7 @@ use base 'Mojo::Message';
use Mojo::Cookie::Response;
use Mojo::Date;
-__PACKAGE__->attr('code', default => sub {200});
+__PACKAGE__->attr(code => sub {200});
__PACKAGE__->attr('message');
# Umarked codes are from RFC 2616 (mostly taken from LWP)
View
@@ -11,8 +11,8 @@ use overload '""' => sub { shift->to_string }, fallback => 1;
use Mojo::ByteStream 'b';
use Mojo::URL;
-__PACKAGE__->attr('pair_separator', default => '&');
-__PACKAGE__->attr('params', default => sub { [] });
+__PACKAGE__->attr(pair_separator => '&');
+__PACKAGE__->attr(params => sub { [] });
# Yeah, Moe, that team sure did suck last night. They just plain sucked!
# I've seen teams suck before,
View
@@ -11,8 +11,8 @@ use overload '""' => sub { shift->to_string }, fallback => 1;
use Mojo::ByteStream 'b';
use Mojo::URL;
-__PACKAGE__->attr([qw/leading_slash trailing_slash/], default => 0);
-__PACKAGE__->attr('parts', default => sub { [] });
+__PACKAGE__->attr([qw/leading_slash trailing_slash/] => 0);
+__PACKAGE__->attr(parts => sub { [] });
sub new {
my $self = shift->SUPER::new();
View
@@ -7,7 +7,7 @@ use warnings;
use base 'Mojo::Transaction';
-__PACKAGE__->attr('safe_post', default => 0);
+__PACKAGE__->attr(safe_post => 0);
# No children have ever meddled with the Republican Party and lived to tell
# about it.
View
@@ -16,10 +16,10 @@ use Carp 'croak';
use Mojo::ByteStream 'b';
use Mojo::Template;
-__PACKAGE__->attr('description', default => 'No description.');
-__PACKAGE__->attr('quiet', default => 0);
-__PACKAGE__->attr('renderer', default => sub { Mojo::Template->new });
-__PACKAGE__->attr('usage', default => "usage: $0\n");
+__PACKAGE__->attr(description => 'No description.');
+__PACKAGE__->attr(quiet => 0);
+__PACKAGE__->attr(renderer => sub { Mojo::Template->new });
+__PACKAGE__->attr(usage => "usage: $0\n");
sub chmod_file {
my ($self, $path, $mod) = @_;
View
@@ -11,10 +11,10 @@ use Mojo::Server::CGI;
use Getopt::Long 'GetOptions';
-__PACKAGE__->attr('description', default => <<'EOF');
+__PACKAGE__->attr(description => <<'EOF');
Start application with CGI backend.
EOF
-__PACKAGE__->attr('usage', default => <<"EOF");
+__PACKAGE__->attr(usage => <<"EOF");
usage: $0 cgi [OPTIONS]
These options are available:
@@ -11,10 +11,10 @@ use Mojo::Server::Daemon;
use Getopt::Long 'GetOptions';
-__PACKAGE__->attr('description', default => <<'EOF');
+__PACKAGE__->attr(description => <<'EOF');
Start application with HTTP 1.1 backend.
EOF
-__PACKAGE__->attr('usage', default => <<"EOF");
+__PACKAGE__->attr(usage => <<"EOF");
usage: $0 daemon [OPTIONS]
These options are available:
@@ -11,10 +11,10 @@ use Mojo::Server::Daemon::Prefork;
use Getopt::Long 'GetOptions';
-__PACKAGE__->attr('description', default => <<'EOF');
+__PACKAGE__->attr(description => <<'EOF');
Start application with preforking HTTP 1.1 backend.
EOF
-__PACKAGE__->attr('usage', default => <<"EOF");
+__PACKAGE__->attr(usage => <<"EOF");
usage: $0 daemon_prefork [OPTIONS]
These options are available:
@@ -9,10 +9,10 @@ use base 'Mojo::Script';
use Mojo::Server::FastCGI;
-__PACKAGE__->attr('description', default => <<'EOF');
+__PACKAGE__->attr(description => <<'EOF');
Start application with FastCGI backend.
EOF
-__PACKAGE__->attr('usage', default => <<"EOF");
+__PACKAGE__->attr(usage => <<"EOF");
usage: $0 fastcgi
EOF
Oops, something went wrong.

0 comments on commit 58599d0

Please sign in to comment.