| 1 | #============================================================================== | ||||||||||
| 2 | # | ||||||||||
| 3 | # Template::Plugin::Procedural | ||||||||||
| 4 | # | ||||||||||
| 5 | # DESCRIPTION | ||||||||||
| 6 | # A Template Plugin to provide a Template Interface to Data::Dumper | ||||||||||
| 7 | # | ||||||||||
| 8 | # AUTHOR | ||||||||||
| 9 | # Mark Fowler <mark@twoshortplanks.com> | ||||||||||
| 10 | # | ||||||||||
| 11 | # COPYRIGHT | ||||||||||
| 12 | # Copyright (C) 2002 Mark Fowler. All Rights Reserved | ||||||||||
| 13 | # | ||||||||||
| 14 | # This module is free software; you can redistribute it and/or | ||||||||||
| 15 | # modify it under the same terms as Perl itself. | ||||||||||
| 16 | # | ||||||||||
| 17 | #============================================================================== | ||||||||||
| 18 | |||||||||||
| 19 | package Template::Plugin::Procedural; | ||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | ▶ | use base 'Template::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 1 | our $VERSION = '3.106'; | |||||||||
| 26 | 1 | ▶ | our $DEBUG = 0 unless defined $DEBUG; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 1 | our $AUTOLOAD; | |||||||||
| 28 | |||||||||||
| 29 | #------------------------------------------------------------------------ | ||||||||||
| 30 | # load | ||||||||||
| 31 | #------------------------------------------------------------------------ | ||||||||||
| 32 | |||||||||||
| 33 | 2 | ▶ | sub load { | ||||||||
|
Subroutine
load: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 34 | 2 | my ($class, $context) = @_; | |||||||||
| 35 | |||||||||||
| 36 | # create a proxy namespace that will be used for objects | ||||||||||
| 37 | 2 | my $proxy = "Template::Plugin::" . $class; | |||||||||
| 38 | |||||||||||
| 39 | # okay, in our proxy create the autoload routine that will | ||||||||||
| 40 | # call the right method in the real class | ||||||||||
| 41 | 1 | ▶ | no strict "refs"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 2 | ▶ | unless( defined( *{ $proxy . "::AUTOLOAD" } ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 2 | ▶ | *{ $proxy . "::AUTOLOAD" } = sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.1
| |||||||||||
| 44 | # work out what the method is called | ||||||||||
| 45 | 7 | $AUTOLOAD =~ s!^.*::!!; | |||||||||
| 46 | |||||||||||
| 47 | 7 | ▶ | print STDERR "Calling '$AUTOLOAD' in '$class'\n" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | if $DEBUG; | ||||||||||
| 49 | |||||||||||
| 50 | # look up the sub for that method (but in a OO way) | ||||||||||
| 51 | 7 | my $uboat = $class->can($AUTOLOAD); | |||||||||
| 52 | |||||||||||
| 53 | # if it existed call it as a subroutine, not as a method | ||||||||||
| 54 | 7 | ▶ | if ($uboat) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 7 | shift @_; | |||||||||
| 56 | 7 | return $uboat->(@_); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | print STDERR "Eeek, no such method '$AUTOLOAD'\n" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | if $DEBUG; | ||||||||||
| 61 | |||||||||||
| 62 | 0 | return ""; | |||||||||
| 63 | 2 | }; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | # create a simple new method that simply returns a blessed | ||||||||||
| 67 | # scalar as the object. | ||||||||||
| 68 | 2 | ▶ | unless( defined( *{ $proxy . "::new" } ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 2 | ▶ | *{ $proxy . "::new" } = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 2 | my $this; | |||||||||
| 71 | 2 | return bless \$this, $_[0]; | |||||||||
| 72 | 2 | }; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 2 | return $proxy; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 1 | 1; | |||||||||
| 79 | |||||||||||
| 80 | __END__ | ||||||||||