| 1 | package Froody::Structure; | ||||||||||||||||||||||||||||
| 2 | 33 | ▶ | use base qw(Froody::Base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 33 | ▶ | use Storable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 33 | our $VERSION = 0.01; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Froody::Structure - object representing the structure used by the response | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # abstract class, see Froody::Method or Froody::ErrorType | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 METHODS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =over | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =item new() | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Create a new reflection object | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =item match_to_regex( "foo.bar.*" ) | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Class method that returns a regular expression that will determine if a string | ||||||||||||||||||||||||||||
| 36 | matches the specification passed in | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub match_to_regex | ||||||||||||||||||||||||||||
| 41 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
match_to_regex: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 1 | my $whatever = shift; | |||||||||||||||||||||||||||
| 43 | 1 | my $query = shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ($query =~ /[^a-zA-Z.*]/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | { Froody::Error->throw("perl.methodcall.param", "Bad method spec '$query'"); } | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | $query =~ s{\.}{\.}g; # dots are dots | |||||||||||||||||||||||||||
| 49 | 1 | $query =~ s/\*/[^.]+/g; # stars are not dots | |||||||||||||||||||||||||||
| 50 | 1 | return qr/^$query$/; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =back | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =over | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item structure | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | A hash reference containing the specification of how the data that will be | ||||||||||||||||||||||||||||
| 62 | returned will be aranged - essentially the blueprint for constructing the | ||||||||||||||||||||||||||||
| 63 | response. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | You probably don't want to create these by hand; The Froody::API::XML | ||||||||||||||||||||||||||||
| 66 | module will create these given a suitable example. See that module documentaion | ||||||||||||||||||||||||||||
| 67 | for more info. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | The structure is a simple hash with a 'xpath' style key pointing to a hash | ||||||||||||||||||||||||||||
| 70 | containing C<elts> (elements) and C<attr> (attributes) arrayrefs. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | { 'people' => | ||||||||||||||||||||||||||||
| 73 | { attr => ['group'], | ||||||||||||||||||||||||||||
| 74 | elts => [qw/person/], | ||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||
| 76 | 'people/person' => | ||||||||||||||||||||||||||||
| 77 | { elts => [qw/name/], | ||||||||||||||||||||||||||||
| 78 | attr => [qw/nick number/], | ||||||||||||||||||||||||||||
| 79 | text => 0, | ||||||||||||||||||||||||||||
| 80 | multi => 1, | ||||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | C<elts> should contain a list of all elements under this node. Each one of these | ||||||||||||||||||||||||||||
| 85 | elements will require a further entry in the hash unless the element contains | ||||||||||||||||||||||||||||
| 86 | only text and cannot be repeated (for example, the title and description | ||||||||||||||||||||||||||||
| 87 | in the above data structure are like this.) | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | The hashrefs may also contain other flags. The C<text> flag can be used to | ||||||||||||||||||||||||||||
| 90 | indicate if it is valid for this node to contain text or not. The C<multi> | ||||||||||||||||||||||||||||
| 91 | flag is used to indicate if there can be repeate occurances of the elements. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | This would mean that the above data structure would validate this XML structure: | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | <people group="frameworks" /> | ||||||||||||||||||||||||||||
| 96 | <person nick="clkao" number="243"> | ||||||||||||||||||||||||||||
| 97 | <name>Chia-liang Kao</name> | ||||||||||||||||||||||||||||
| 98 | </person> | ||||||||||||||||||||||||||||
| 99 | <person nick="Trelane" number="234"> | ||||||||||||||||||||||||||||
| 100 | <name>Mark Fowler</name> | ||||||||||||||||||||||||||||
| 101 | </person> | ||||||||||||||||||||||||||||
| 102 | <person nick="Nichloas" number="238"> | ||||||||||||||||||||||||||||
| 103 | <name>Nicholas Clark</name> | ||||||||||||||||||||||||||||
| 104 | </person> | ||||||||||||||||||||||||||||
| 105 | <person nick="nnunley" number="243"> | ||||||||||||||||||||||||||||
| 106 | <name>Norman Nunley</name> | ||||||||||||||||||||||||||||
| 107 | </person> | ||||||||||||||||||||||||||||
| 108 | <person nick="skugg" number="214"> | ||||||||||||||||||||||||||||
| 109 | <name>Stig Brautaset</name> | ||||||||||||||||||||||||||||
| 110 | </person> | ||||||||||||||||||||||||||||
| 111 | <person nick="jerakeen" number="235"> | ||||||||||||||||||||||||||||
| 112 | <name>Tom Insam</name> | ||||||||||||||||||||||||||||
| 113 | </person> | ||||||||||||||||||||||||||||
| 114 | Frameworks is a department of Fotango. We work on lots of | ||||||||||||||||||||||||||||
| 115 | software, including writing tools like Froody. | ||||||||||||||||||||||||||||
| 116 | </people> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub structure | ||||||||||||||||||||||||||||
| 121 | 341 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
structure: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 341 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | 341 | ▶ | return $self->{structure} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 268 | ▶ | if (ref($_[0])) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 268 | { $self->{structure} = Storable::dclone shift } | |||||||||||||||||||||||||||
| 126 | else | ||||||||||||||||||||||||||||
| 127 | 0 | { $self->{structure} = shift } | |||||||||||||||||||||||||||
| 128 | 268 | return $self; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =item example_response | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | An example of the response we expect to see when this is rendered. This should | ||||||||||||||||||||||||||||
| 134 | be a Froody::Response object. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | sub example_response | ||||||||||||||||||||||||||||
| 139 | 186 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
example_response: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | 186 | my $self = shift; | |||||||||||||||||||||||||||
| 141 | 186 | ▶ | return $self->{example_response} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 177 | my $rsp = shift; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 177 | ▶ | unless (blessed($rsp) && $rsp->isa("Froody::Response")) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($rsp) and $rsp->isa("Froody::Response")
MC/DC100%2/2
builtin::blessed($rsp) and $rsp->isa("Froody::Response")
builtin::blessed($rsp)
$rsp->isa("Froody::Response")
Truth table100%3/3
A and B
A= builtin::blessed($rsp)B= $rsp->isa("Froody::Response")
| |||||||||||||||||||||||||||||
| 145 | 2 | { Froody::Error->throw("perl.methodcall.param", "example_response only accepts Froody::Response objects not a '$rsp'"); } | |||||||||||||||||||||||||||
| 146 | 175 | $self->{example_response} = $rsp; | |||||||||||||||||||||||||||
| 147 | 175 | return $self; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =back | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head1 BUGS | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | None known. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | Please report any bugs you find via the CPAN RT system. | ||||||||||||||||||||||||||||
| 157 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody> | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Copyright Fotango 2005. All rights reserved. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Please see the main L<Froody> documentation for details of who has worked | ||||||||||||||||||||||||||||
| 164 | on this project. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 167 | the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | L<Froody>, L<Froody::Repository>, L<Froody::Method>, L<Froody::ErrorType> | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 33 | 1; | |||||||||||||||||||||||||||