| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package Goo::Thing::pm::MethodMaker; | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | ############################################################################### | 
| 6 |  |  |  |  |  |  | # Nigel Hamilton | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | # Copyright Nigel Hamilton 2005 | 
| 9 |  |  |  |  |  |  | # All Rights Reserved | 
| 10 |  |  |  |  |  |  | # | 
| 11 |  |  |  |  |  |  | # Author:       Nigel Hamilton | 
| 12 |  |  |  |  |  |  | # Filename:     Goo::Thing::pm::MethodMaker.pm | 
| 13 |  |  |  |  |  |  | # Description:  Create a method body | 
| 14 |  |  |  |  |  |  | # | 
| 15 |  |  |  |  |  |  | # Date          Change | 
| 16 |  |  |  |  |  |  | # ----------------------------------------------------------------------------- | 
| 17 |  |  |  |  |  |  | # 15/02/2005    Auto generated file | 
| 18 |  |  |  |  |  |  | # 15/02/2005    Needed to reuse this code and simplify ProgramMaker | 
| 19 |  |  |  |  |  |  | # | 
| 20 |  |  |  |  |  |  | ############################################################################### | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 1 |  |  | 1 |  | 8 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 47 |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 1 |  |  | 1 |  | 7 | use Goo::Object; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 38 |  | 
| 25 | 1 |  |  | 1 |  | 8 | use Goo::Prompter; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 21 |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 1 |  |  | 1 |  | 635 | use Goo::Thing::pm::Method; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 272 |  | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | our @ISA = ("Goo::Object"); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | ############################################################################### | 
| 34 |  |  |  |  |  |  | # | 
| 35 |  |  |  |  |  |  | # generate_methods - add methods to the progeam | 
| 36 |  |  |  |  |  |  | # | 
| 37 |  |  |  |  |  |  | ############################################################################### | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub generate_methods { | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 |  |  | 0 | 1 |  | my ($this, $has_constructor) = @_; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 0 |  |  |  |  |  | my @methods; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 |  |  |  |  |  | while (1) { | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 0 |  |  |  |  |  | my $method = Goo::Prompter::ask("Add a method?"); | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 0 | 0 |  |  |  |  | if ($method eq "") { last; } | 
|  | 0 |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | my $description = Goo::Prompter::ask("Enter a description for $method?"); | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 0 |  |  |  |  |  | my @parameters = | 
| 54 |  |  |  |  |  |  | Goo::Prompter::keep_asking("enter a parameter for $method (mandatories first)?"); | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | # prepend a $ sign if it doesn't have one | 
| 57 | 0 | 0 |  |  |  |  | @parameters = map { $_ =~ /\$/ ? $_ : '$' . $_ } | 
|  | 0 |  |  |  |  |  |  | 
| 58 | 0 |  |  |  |  |  | grep { $_ !~ /this/ } @parameters; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 0 | 0 |  |  |  |  | if ($has_constructor) { | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | # add this to the parameters - if we have a constructor | 
| 63 |  |  |  |  |  |  | # $this is the first parameter for all OO classes | 
| 64 | 0 |  |  |  |  |  | unshift(@parameters, '$this'); | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 |  |  |  |  |  | my $signature = join(', ', @parameters); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  |  | my $m = | 
| 70 |  |  |  |  |  |  | Goo::Thing::pm::Method->new( | 
| 71 |  |  |  |  |  |  | { method      => $method, | 
| 72 |  |  |  |  |  |  | signature   => $signature, | 
| 73 |  |  |  |  |  |  | description => $description | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  | ); | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | # print "pushing new method on .... ".$m->to_string(); | 
| 78 | 0 |  |  |  |  |  | push(@methods, $m); | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 0 |  |  |  |  |  | return @methods; | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | 1; | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | __END__ | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =head1 NAME | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | Goo::Thing::pm::MethodMaker - Create a method body | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | use Goo::Thing::pm::MethodMaker; | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head1 METHODS | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =over | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =item generate_methods | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | add methods to the progeam | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =back | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head1 AUTHOR | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | Nigel Hamilton <nigel@trexy.com> | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 120 |  |  |  |  |  |  |  |