Catalyst
       Enhanced
10 Things you Should Know, but may not.

             by Jay Shirley




                   1
1. Plugins


    2
DON’T
  3
When?


  4
Really, don’t.


      5
What about
Catalyst::Plugin::Authenticati
             on?



              6
$c->user
$c->session

     7
2. Debugging


     8
perl 5.10’s
“Unknown Error”

       9
?dump_info=1


     10
Write Tests


     11
3. Configuration


       12
package
 MyApp::Controller::Foo;

__PACKAGE__->config(
    ‘foo’ => ‘bar’
);

           13
MyApp->config(
 ‘Controller::Foo’=>{
     ‘foo’ => ‘bar’
   }
);


           14
Use accessors


      15
has ‘foo’ => (
   is => ‘rw’,
   isa => ‘Str’
);


           16
__PACKAGE__
   ->mk_accessors(‘foo’)



           17
Use $self


    18
$self->{‘foo’}




      19
myapp_local.(yml|conf)
   myapp.(yml|conf)
       MyApp.pm
MyApp::Controller::Foo


          20
Do Not:


   21
package Controller::Foo;
__PACKAGE__
 ->config(‘foo’=>‘bar’);

sub method : Local {
  my ($self, $c) = @_;
  $c->config
  ...
package Controller::Foo;
__PACKAGE__
 ->config(‘foo’=>‘bar’);

sub COMPONENT {
  my ($self, $c, $config)=@_;
  $config->{f...
Always use $self


       24
Overuse Config


      25
4. Better
Controllers

     26
Base Classes!


      27
Just Config


     28
Good Example:

Catalyst::Controller::DBIC::A
             PI


              29
5. Chained


    30
Point A to B


     31
Action != URI


      32
sub foo : Local { }


         33
sub foo : Local { }


         34
Say what?


    35
Let me start over


        36
/foo/123/edit


      37
It’s like ‘auto’


       38
sub setup_object :
    Chained(‘/’)
    CaptureArgs(1) { }



          39
sub setup_object :
    Chained(‘/’)
    CaptureArgs(1) { }



          40
/.../123/edit


      41
sub method ... {
    my ( $self, $c, @args ) = @_;
    # @args == ( 123 );
}



                 42
sub edit :
  Chained(‘setup_object’)
  Args(0) { }




            43
sub edit :
  Chained(‘setup_object’)
  Args(0) { }




            44
sub edit :
  Chained(‘setup_object’)
  Args(0) { }




            45
/.../123/edit


      46
Really, it’s
awesome.

     47
http://github.com/jshirley
   catalystx-example-chained




               48
6. Deployment


      49
FastCGI


   50
“Static”


   51
External


   52
Zero Downtime


      53
Viva la
Revolucion

    54
Work in Progress



       55
mod_perl


   56
You would know


      57
HTTP::Prefork


      58
Experimental?


      59
Zero Downtime?


      60
7. Logging


    61
More than
Catalyst::Log

      62
Catalyst::Log::Log4per
           l


          63
Use standard
  methods

     64
The little known
 $c->_dump()

       65
8.
Action(‘Classes’)

        66
Better with 5.8


       67
Catalyst::Controller::ActionR
             ole




              68
sub action :
Does(‘moo’)


     69
Roles!


  70
See Moose::Role



       71
Action(‘Classes’)


        72
When to use


     73
9. local::lib


      74
Vendor Perl = Not
     Good


        75
Not bad, not
   good

     76
Use Makefile.PL


       77
Application is
 User Level

      78
Simple!
perl -Mlocal::lib


        79
Problem?
rm -Rf $HOME/perl5


        80
or, create more!


       81
10. Contributing


       82
Documentation


      83
Tests!


  84
Blog! Evangelize!


        85
Launch
Applications

     86
More
 Applications =
More Developers

       87
If you build it,
they will come.

        88
89
Upcoming SlideShare
Loading in …5
×

10 Catalyst Tips

4,473 views

Published on

Here's a presentation I did for the Japanese Perl Association on April 21st, 2009.

It covers 10 aspects of Catalyst that may not be documented or discussed as much as they could be, that are very useful.

Published in: Technology
  • Be the first to comment

10 Catalyst Tips

  1. 1. Catalyst Enhanced 10 Things you Should Know, but may not. by Jay Shirley 1
  2. 2. 1. Plugins 2
  3. 3. DON’T 3
  4. 4. When? 4
  5. 5. Really, don’t. 5
  6. 6. What about Catalyst::Plugin::Authenticati on? 6
  7. 7. $c->user $c->session 7
  8. 8. 2. Debugging 8
  9. 9. perl 5.10’s “Unknown Error” 9
  10. 10. ?dump_info=1 10
  11. 11. Write Tests 11
  12. 12. 3. Configuration 12
  13. 13. package MyApp::Controller::Foo; __PACKAGE__->config( ‘foo’ => ‘bar’ ); 13
  14. 14. MyApp->config( ‘Controller::Foo’=>{ ‘foo’ => ‘bar’ } ); 14
  15. 15. Use accessors 15
  16. 16. has ‘foo’ => ( is => ‘rw’, isa => ‘Str’ ); 16
  17. 17. __PACKAGE__ ->mk_accessors(‘foo’) 17
  18. 18. Use $self 18
  19. 19. $self->{‘foo’} 19
  20. 20. myapp_local.(yml|conf) myapp.(yml|conf) MyApp.pm MyApp::Controller::Foo 20
  21. 21. Do Not: 21
  22. 22. package Controller::Foo; __PACKAGE__ ->config(‘foo’=>‘bar’); sub method : Local { my ($self, $c) = @_; $c->config ->{‘Controller::Foo’} ->{foo}; } 22
  23. 23. package Controller::Foo; __PACKAGE__ ->config(‘foo’=>‘bar’); sub COMPONENT { my ($self, $c, $config)=@_; $config->{foo}; # NO! } 23
  24. 24. Always use $self 24
  25. 25. Overuse Config 25
  26. 26. 4. Better Controllers 26
  27. 27. Base Classes! 27
  28. 28. Just Config 28
  29. 29. Good Example: Catalyst::Controller::DBIC::A PI 29
  30. 30. 5. Chained 30
  31. 31. Point A to B 31
  32. 32. Action != URI 32
  33. 33. sub foo : Local { } 33
  34. 34. sub foo : Local { } 34
  35. 35. Say what? 35
  36. 36. Let me start over 36
  37. 37. /foo/123/edit 37
  38. 38. It’s like ‘auto’ 38
  39. 39. sub setup_object : Chained(‘/’) CaptureArgs(1) { } 39
  40. 40. sub setup_object : Chained(‘/’) CaptureArgs(1) { } 40
  41. 41. /.../123/edit 41
  42. 42. sub method ... { my ( $self, $c, @args ) = @_; # @args == ( 123 ); } 42
  43. 43. sub edit : Chained(‘setup_object’) Args(0) { } 43
  44. 44. sub edit : Chained(‘setup_object’) Args(0) { } 44
  45. 45. sub edit : Chained(‘setup_object’) Args(0) { } 45
  46. 46. /.../123/edit 46
  47. 47. Really, it’s awesome. 47
  48. 48. http://github.com/jshirley catalystx-example-chained 48
  49. 49. 6. Deployment 49
  50. 50. FastCGI 50
  51. 51. “Static” 51
  52. 52. External 52
  53. 53. Zero Downtime 53
  54. 54. Viva la Revolucion 54
  55. 55. Work in Progress 55
  56. 56. mod_perl 56
  57. 57. You would know 57
  58. 58. HTTP::Prefork 58
  59. 59. Experimental? 59
  60. 60. Zero Downtime? 60
  61. 61. 7. Logging 61
  62. 62. More than Catalyst::Log 62
  63. 63. Catalyst::Log::Log4per l 63
  64. 64. Use standard methods 64
  65. 65. The little known $c->_dump() 65
  66. 66. 8. Action(‘Classes’) 66
  67. 67. Better with 5.8 67
  68. 68. Catalyst::Controller::ActionR ole 68
  69. 69. sub action : Does(‘moo’) 69
  70. 70. Roles! 70
  71. 71. See Moose::Role 71
  72. 72. Action(‘Classes’) 72
  73. 73. When to use 73
  74. 74. 9. local::lib 74
  75. 75. Vendor Perl = Not Good 75
  76. 76. Not bad, not good 76
  77. 77. Use Makefile.PL 77
  78. 78. Application is User Level 78
  79. 79. Simple! perl -Mlocal::lib 79
  80. 80. Problem? rm -Rf $HOME/perl5 80
  81. 81. or, create more! 81
  82. 82. 10. Contributing 82
  83. 83. Documentation 83
  84. 84. Tests! 84
  85. 85. Blog! Evangelize! 85
  86. 86. Launch Applications 86
  87. 87. More Applications = More Developers 87
  88. 88. If you build it, they will come. 88
  89. 89. 89

×