| 1 | # Encoding and name #_{ | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Geo::OSM::DBI::Primitive::Way - Derivation of L<< Geo::OSM::Primitive::Way >> and L<<Geo::OSM::DBI::Primitive >>, to be used with L<< Geo::OSM::DBI >>. | ||
| 7 | |||
| 8 | =cut | ||
| 9 | package Geo::OSM::DBI::Primitive::Way; | ||
| 10 | #_} | ||
| 11 | #_{ use … | ||
| 12 | use warnings; | ||
| 13 | use strict; | ||
| 14 | |||
| 15 | use utf8; | ||
| 16 | use Carp; | ||
| 17 | |||
| 18 | use Geo::OSM::Primitive::Way; | ||
| 19 | our @ISA=qw(Geo::OSM::Primitive::Way Geo::OSM::DBI::Primitive); | ||
| 20 | |||
| 21 | #_} | ||
| 22 | our $VERSION = 0.01; | ||
| 23 | #_{ Synopsis | ||
| 24 | |||
| 25 | =head1 SYNOPSIS | ||
| 26 | |||
| 27 | … | ||
| 28 | |||
| 29 | =cut | ||
| 30 | #_} | ||
| 31 | #_{ Overview | ||
| 32 | |||
| 33 | =head1 OVERVIEW | ||
| 34 | |||
| 35 | … | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | #_} | ||
| 40 | #_{ Methods | ||
| 41 | |||
| 42 | =head1 METHODS | ||
| 43 | =cut | ||
| 44 | |||
| 45 | sub new { #_{ | ||
| 46 | #_{ POD | ||
| 47 | |||
| 48 | =head2 new | ||
| 49 | |||
| 50 | my $osm_dbi = Geo::OSM::DBI->new(…); | ||
| 51 | |||
| 52 | new($osm_way_id, $osm_dbi); | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | #_} | ||
| 57 | |||
| 58 | my $class = shift; | ||
| 59 | my $id = shift; | ||
| 60 | my $osm_dbi = shift; | ||
| 61 | |||
| 62 | my $self = $class->SUPER::new($id); | ||
| 63 | |||
| 64 | croak "not a Geo::OSM::DBI::Primitive::Way" unless $self -> isa('Geo::OSM::DBI::Primitive::Way'); | ||
| 65 | |||
| 66 | $self->_init_geo_osm_dbi_primitive($osm_dbi); | ||
| 67 | |||
| 68 | return $self; | ||
| 69 | |||
| 70 | } #_} | ||
| 71 | sub nodes { #_{ | ||
| 72 | #_{ POD | ||
| 73 | |||
| 74 | =head2 nodes | ||
| 75 | |||
| 76 | my @nodes = $way -> nodes(); | ||
| 77 | |||
| 78 | Returns the nodes that the way conisist of. | ||
| 79 | |||
| 80 | B<TODO> Should this method consider the nodes in the cache (L<Geo::OSM::DBI::Primitive::Node/_set_cache_nodes>) | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | #_} | ||
| 85 | |||
| 86 | my $self = shift; | ||
| 87 | |||
| 88 | my $sth = $self->{osm_dbi}->{dbh}->prepare( #_{ | ||
| 89 | " select | ||
| 90 | nd.id, | ||
| 91 | nd.lat, | ||
| 92 | nd.lon | ||
| 93 | from | ||
| 94 | nod_way nw join | ||
| 95 | nod nd on nw.nod_id = nd.id | ||
| 96 | where | ||
| 97 | nw.way_id = ? | ||
| 98 | order by | ||
| 99 | order_ | ||
| 100 | ") or croak; #_} | ||
| 101 | $sth->execute($self->{id}); | ||
| 102 | my @ret; | ||
| 103 | while (my $r = $sth->fetchrow_hashref) { #_{ | ||
| 104 | my $node = Geo::OSM::DBI::Primitive::Node->new($r->{id}, $self->{osm_dbi}, $r->{lat}, $r->{lon}); | ||
| 105 | |||
| 106 | push @ret, $node; | ||
| 107 | } #_} | ||
| 108 | |||
| 109 | return @ret; | ||
| 110 | |||
| 111 | } #_} | ||
| 112 | |||
| 113 | #_} | ||
| 114 | #_{ POD: Copyright and license | ||
| 115 | |||
| 116 | =head1 COPYRIGHT and LICENSE | ||
| 117 | |||
| 118 | Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved. | ||
| 119 | |||
| 120 | This program is free software; you can redistribute it and/or modify it | ||
| 121 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 122 | copy of the full license at: L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | #_} | ||
| 127 | #_{ POD: Source Code | ||
| 128 | |||
| 129 | =head1 SOURCE CODE | ||
| 130 | |||
| 131 | The source code is on L<< github|https://github.com/ReneNyffenegger/perl-Geo-OSM-DBI >>. Meaningful pull requests are welcome. | ||
| 132 | |||
| 133 | =cut | ||
| 134 | |||
| 135 | #_} |