Skip to content

Instantly share code, notes, and snippets.

@jhannah
Created March 19, 2014 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhannah/9653164 to your computer and use it in GitHub Desktop.
Save jhannah/9653164 to your computer and use it in GitHub Desktop.
Perl Catalyst::Utils
➜ Jay-Hannahs-iMac:Catalyst-Runtime git:(master) git remote -v
origin catagits@git.shadowcat.co.uk:Catalyst-Runtime (fetch)
origin catagits@git.shadowcat.co.uk:Catalyst-Runtime (push)
➜ Jay-Hannahs-iMac:Catalyst-Runtime git:(master) git blame lib/Catalyst/Utils.pm
...
b0ad47c1 (Dan Dascalescu 2009-06-11 07:27:56 +0000 379) 2) Export $COLUMNS from your shell.
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 380)
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 381) (Warning to bash users: 'echo $COLUMNS' may be showing you the bash
b0ad47c1 (Dan Dascalescu 2009-06-11 07:27:56 +0000 382) variable, not $ENV{COLUMNS}. 'export COLUMNS=$COLUMNS' and you should see
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 383) that 'env' now lists COLUMNS.)
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 384)
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 385) As last resort, default value of 80 chars will be used.
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 386)
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 387) =cut
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 388)
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 389) my $_term_width;
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 390)
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 391) sub term_width {
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 392) return $_term_width if $_term_width;
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 393)
ab61f021 (Karen Etheridge 2013-09-13 14:03:40 -0700 394) my $width;
ab61f021 (Karen Etheridge 2013-09-13 14:03:40 -0700 395) eval '
ab61f021 (Karen Etheridge 2013-09-13 14:03:40 -0700 396) require Term::Size::Any;
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 397) my ($columns, $rows) = Term::Size::Any::chars;
ab61f021 (Karen Etheridge 2013-09-13 14:03:40 -0700 398) $width = $columns;
ab61f021 (Karen Etheridge 2013-09-13 14:03:40 -0700 399) 1;
ab61f021 (Karen Etheridge 2013-09-13 14:03:40 -0700 400) ' or do {
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 401) $width = $ENV{COLUMNS}
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 402) if exists($ENV{COLUMNS})
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 403) && $ENV{COLUMNS} =~ m/^\d+$/;
ab61f021 (Karen Etheridge 2013-09-13 14:03:40 -0700 404) };
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 405)
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 406) $width = 80 unless ($width && $width >= 80);
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 407) return $_term_width = $width;
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 408) }
39fc2ce1 (Jay Hannah 2009-01-22 01:45:16 +0000 409)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 410)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 411) =head2 resolve_namespace
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 412)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 413) Method which adds the namespace for plugins and actions.
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 414)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 415) __PACKAGE__->setup(qw(MyPlugin));
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 416)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 417) # will load Catalyst::Plugin::MyPlugin
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 418)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 419) =cut
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 420)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 421)
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 422) sub resolve_namespace {
5d8129e9 (Moritz Onken 2009-06-07 12:28:53 +0000 423) my $appnamespace = shift;
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 424) my $namespace = shift;
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 425) my @classes = @_;
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 426) return String::RewritePrefix->rewrite({
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 427) q[] => qq[${namespace}::],
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 428) q[+] => q[],
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 429) (defined $appnamespace
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 430) ? (q[~] => qq[${appnamespace}::])
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 431) : ()
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 432) ),
196932de (Florian Ragwitz 2009-06-26 19:45:45 +0000 433) }, @classes);
17b3d800 (Moritz Onken 2009-06-06 13:33:53 +0000 434) }
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment